[Tex/LaTex] tabular whole page lr

horizontal alignmenttables

I have some problems with creating a table. I'd like to have a table with no borders that fills the total text width, with 2 columns aligned right and left respectively. However, I can either make a table with the total text width or aligned left and right but not both. I tried to do it with >{\raggedright \arraybackslash}m{0.05\linewidth} with adding a 3rd. empty column, but I can't make it to align left or right.

Could someone please help ?

basic code:

\begin{tabular}{lr}
a & b \\
  & d
\end{tabular}

Best Answer

First with tabularx, you can make a column right aligned by

>{\raggedleft\arraybackslash}X

while X column type takes care of the column width automatically.

\documentclass{article}
\usepackage{tabularx}
\usepackage{showframe}  %% jusr for demo
\begin{document}
  \noindent
  \begin{tabularx}{\textwidth}{X>{\raggedleft\arraybackslash}X}
    Left & Right\\
    Left & Right
  \end{tabularx}
\end{document}

Next with tabular*. Here we use lr columns but the space in between is filled with a total width equal to \textwidth.

\documentclass{article}
\usepackage{array}
\usepackage{showframe}  %% jusr for demo
\begin{document}
  \noindent
  \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r}
    Left & Right\\
    Left & Right
  \end{tabular*}
\end{document}

With p column type and tabular, we have to calculate the width of columns and then issue \raggedleft for second column.

\documentclass{article}
\usepackage{array}
\usepackage{showframe}  %% jusr for demo
\begin{document}
  \noindent
  \begin{tabular}{p{\dimexpr0.5\textwidth-2\tabcolsep\relax}
                  >{\raggedleft\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep\relax}}
    Left & Right\\
    Left & Right
  \end{tabular}
\end{document}

enter image description here

Related Question