0

I'm new with LaTeX. I want to have two tables. The first table renders fine. For the second table, I want it to take full page width and I want text from first column to be aligned left and text from second column to be aligned right.

I have tried the following based on some researches, but table 2 is not taking full with and while the alignment inside columns is as I expect, the table itself is aligned left. (I'm not sure what htbp is, it comes from some example.)

\begin{center} \Large
    \begin{tabular}{ l r }  
        \emph{Text1} & Text2\\ 
        \emph{Text3} & Text4
    \end{tabular}
\end{center}

\vskip 7cm

\begin{table}[htbp]
    \centering
        \begin{tabularx}{\textwidth}{l r}
            \ Text5 & Text6\\
            \ Text7 & Text8\\
            \ Text9 & Text10\\
            \ Text11 & Text12\\
            \ Text13 & Text14
        \end{tabularx}
\end{table}

When I try the following, all previous elements on my page get extra spaces, like the whole page is stretched and second table ends on next page, which should not happen.

\begin{center} \Large
    \begin{tabular}{ l r }  
        \emph{Text1} & Text2\\ 
        \emph{Text3} & Text4
    \end{tabular}
\end{center}

\vskip 9cm

\begin{center} \Large
    \begin{tabularx}{\textwidth}{ l r }
        \ Text5 & Text6\\
        \ Text7 & Text8\\
        \ Text9 & Text10\\
        \ Text11 & Text12\\
        \ Text13 & Text14
    \end{tabularx}
\end{center}
  • A rabularx environment should have at least one X column. – Bernard Feb 12 at 8:50
  • What is one X column? – TTT Feb 12 at 8:50
  • It is defined by the tabularx package : the X columns share the remaining space on the line, after the other columns have been placed. – Bernard Feb 12 at 8:53
  • 1
    What about using \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l r @{}} Text5 & Text6\\ Text7 & Text8\\ Text9 & Text10\\ Text11 & Text12\\ Text13 & Text14 \end{tabular*}? Most likely this will give you the desired result. – leandriis Feb 12 at 9:00
  • 2
    Youi should post a complete (minimal) code reproducing the problem. – Bernard Feb 12 at 9:04
2

Below is an MWE (Minimal Working Example), which cover most of the comments in your question:

\documentclass{article}
\usepackage{tabularx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum} % generate dummy text filler

\begin{document}
\begin{center} 
\Large
    \begin{tabular}{ l r }
        \emph{Text1} & Text2\\
        \emph{Text3} & Text4
    \end{tabular}
\end{center}

\lipsum[11]% for dummy text

\begin{center} \Large
    \begin{tabularx}{\textwidth}{ X >{\raggedleft\arraybackslash}X}
         Text5  & Text6\\
         Text7  & Text8\\
         Text9  & Text10\\
         Text11 & Text12\\
         Text13 & Text14
    \end{tabularx}
\end{center}
However, people usual add to table at least top and bottom lines:
\begin{center}
\Large
    \begin{tabular}{ l r }
        \hline
        \emph{Text1} & Text2    \\ 
        \emph{Text3} & Text4    \\
        \hline
    \end{tabular}
\end{center}

\begin{center} \Large
    \begin{tabularx}{\textwidth}{ X >{\raggedleft\arraybackslash}X}
        \hline
         Text5  & Text6     \\
         Text7  & Text8     \\
         Text9  & Text10    \\
         Text11 & Text12    \\
         Text13 & Text14    \\
        \hline
    \end{tabularx}
\end{center}
\end{document}

which generate:

enter image description here

(red lines show page layout)

I strongly encourage you to read some introductory text about tables. For example wiki: latex tables.

For table design, you may choose environments, as tabular, which is part of LaTeX kernel, tabularx, tabulary, longtable, xltabular etc, which are provided by packages of the same name.

1

I actually want each column to take 50% width

mwe

\documentclass{article}
\usepackage{booktabs} % nice rules
\usepackage{tabularx,array}
\newcolumntype{L}{>{\raggedleft\arraybackslash}X}
\begin{document}
\begin{tabularx}{.3\textwidth}{XL}
\toprule
Text5 & Text6\\
Text13 & Text14\\
\bottomrule
\end{tabularx}
\end{document}

I want it to take full page width

I refuse to make such aberration with only two narrow columns, but how change .3\textwidth is obvious, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.