Fixed: Table Cutting on the Right side in LaTeX for wide table

I usually work in LaTeX for small documents that do not include many graphics and tables. But recently I need to insert a wide table in my LaTeX doc. I saw that the right side of the table is cutting and I can not see the complete table on the page. In this tutorial, I will show you how to fix the Right side of a table cutting for a wide table in LaTeX. When the LaTeX table is wider than the page, we face this issue.

First of all, I will show you a sample LaTeX table that has longer content. In this way you can understand what I faced and how I fixed that:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{geometry}
\geometry{margin=1in}

\begin{document}

\begin{table}[ht]
\centering
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt} % Intentionally wide for demonstration
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Vegetable} & \textbf{Companion Plant} & \textbf{Benefit} & \textbf{Distance} \\
\hline
Tomato & Eggplant & Demo Text Demo Text Demo Text Demo Text Demo Text Demo Text Demo Text Demo Text Demo Text Demo Text \\
\hline
\end{tabular}
\caption{Sample Wide Table}
\end{table}

\end{document}

Output:

Right side of a table cutting LaTeX

You can see in the output that the table exceeds the page margin and gets cut off on the right side.

First I will show you the method that I used to fix it:

\setlength{\tabcolsep}{6pt}

I have set 6pt here, if your text is still wider, then reduce the 6pt value. You can reduce it to 0pt. That’s the best you can do. But if it’s still getting out of the page then you can change the font size to a smaller size to fit in the page.

But do not set this to a negative pt value as it will be out of the vertical lines of your table.

Fix the table cutting issue on the right side using m{width} in LaTeX

The best method to solve the issue is to use m{width} it in the tabular environment.

Let’s see it with a demo table:

Let’s say I have a table like this:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{geometry}
\geometry{margin=1in}
\usepackage{lipsum} % For generating lorem ipsum text

\begin{document}

\begin{table}[ht]
\centering
\arrayrulecolor{black}
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt} % Increased padding for overflow demonstration

\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} \\
\hline
\lipsum[1][1-4] & \lipsum[1][5-10] & \lipsum[1][11-15] & \lipsum[1][16-20] \\
\hline
\lipsum[2][1-4] & \lipsum[2][5-10] & \lipsum[2][11-15] & \lipsum[2][16-20] \\
\hline
\lipsum[3][1-4] & \lipsum[3][5-10] & \lipsum[3][11-15] & \lipsum[3][16-20] \\
\hline
\end{tabular}

\caption{Sample Table with Lorem Ipsum Text (Cutting Issue)}
\end{table}

\end{document}

Output:

LaTeX table Wider than Page

Fixing:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{geometry}
\geometry{margin=1in}
\usepackage{array}
\usepackage{lipsum} % For generating lorem ipsum text

\begin{document}

\begin{table}[ht]
\centering
\arrayrulecolor{black}
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{6pt} % Reduced padding to prevent cutting

\begin{tabular}{|>{\raggedright\arraybackslash}m{3cm}|>{\raggedright\arraybackslash}m{4cm}|>{\raggedright\arraybackslash}m{4cm}|>{\raggedright\arraybackslash}m{2cm}|}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} \\
\hline
\lipsum[1][1-4] & \lipsum[1][5-10] & \lipsum[1][11-15] & \lipsum[1][16-20] \\
\hline
\lipsum[2][1-4] & \lipsum[2][5-10] & \lipsum[2][11-15] & \lipsum[2][16-20] \\
\hline
\lipsum[3][1-4] & \lipsum[3][5-10] & \lipsum[3][11-15] & \lipsum[3][16-20] \\
\hline
\end{tabular}

\caption{Sample Table with Lorem Ipsum Text and Fixed Alignment}
\end{table}

\end{document}

 

Output:

m{width} latexIf you are still facing any issues, do not hesitate to let me know in the comment section. I will fix it for you.

Leave a Reply

Your email address will not be published. Required fields are marked *