2

I want to align this table. This is mycode

\documentclass[a4paper, 12pt]{article}
\usepackage[left=15mm,right=20mm,top=20 mm,bottom=20mm]{geometry}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\begin{longtable}{|p{10.8 cm}|p{6 cm}|}
\hline 
\multicolumn{1}{|c|}{\textbf{\textit{Solve}}}&\multicolumn{1}{|c|}{\textbf{\textit{Result}}} \\
\hline 
 &\\
 &\\
 &\\
 &\\
 &\\
 &\\
&\\
 \hline 
\end{longtable}
\end{document}

enter image description here

How to align this table fit page width when I change my set up in geometry?

2 Answers 2

6

The width of the text block is \textwidth the width of the table is the width of your cells plus 2\tabcolsep padding for each cell plus \ararryrulewidth for each vertical line so

\documentclass[a4paper, 12pt]{article}
\usepackage[left=15mm,right=20mm,top=20 mm,bottom=20mm]{geometry}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\begin{longtable}{
|p{0.7\dimexpr \textwidth-3\arrayrulewidth-4\tabcolsep\relax}|
 p{0.3\dimexpr \textwidth-3\arrayrulewidth-4\tabcolsep\relax}|
}
\hline 
\multicolumn{1}{|c|}{\textbf{\textit{Solve}}}&\multicolumn{1}{|c|}{\textbf{\textit{Result}}} \\
\hline 
 &\\
 &\\
 &\\
 &\\
 &\\
 &\\
&\\
 \hline 
\end{longtable}

\end{document}

3

You can use the tabularx package to automatically calculate the size of some columns.

The basic command to use is

\begin{tabularx}{\textwidth}{|X|X|}

That command creates a table taking the width of the text with two columns. From the tabularx (texdoc tanbularx) manual:

Normally all X columns in a single table are set to the same width, however it is possible to make tabularx set them to different widths. A preamble argument of {>{\hsize=.5\hsize}X>{\hsize=1.5\hsize}X} specifies two columns, the second will be three times as wide as the first. However if you want to play games like this you should follow the following two rules.

• Make sure that the sum of the widths of all the X columns is unchanged. (In the above example, the new widths still add up to twice the default width, the same as two standard X columns.)

• Do not use \multicolumn entries which cross any X column. As with most rules, these may be broken if you know what you are doing.

1
  • Will this also have the functionality to span across multiple pages?
    – HQuser
    Commented Aug 22, 2020 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .