1

This a follow up to this post. I need the content of the second cell inside tabular, to align with the edge of the body of text. \raggedleft comes close, but it extends by \marginparsep. I found a manual way to do it. I'm looking for an automated way.

\documentclass{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[showframe]{geometry}
\ExplSyntaxOn

\dim_new:N \secondlen
\dim_set:Nn\secondlen{0.5\textwidth}
\dim_sub:Nn\secondlen{\marginparsep}

\ExplSyntaxOff
\begin{document}
\ExplSyntaxOn
\dim_use:N\secondlen
\ExplSyntaxOff

\noindent\begin{tabular}
  {@{}>{\raggedright}p{0.5\textwidth}>{\raggedleft\arraybackslash}p{204.0023pt}@{}}
  \lipsum[1][1] & \lipsum[1][2]
\end{tabular}

\end{document}

enter image description here enter image description here

1 Answer 1

1

From your description, I understand that you want a table with two equally wide columns, the contents of the first column aligned the the left, the contents of the second column right-aligned, with the overall table width being equal to the lineiwdth.

To achieve that, you can either manually calculate the required column widths using p{\dimexpr 0.5\linewidth-\tabcolsep} or you can let tabularx do that job for you. Both versions result in the following output:

enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[showframe]{geometry}
\usepackage{tabularx}

\begin{document}

\noindent
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{\dimexpr 0.5\linewidth-\tabcolsep}>{\raggedleft\arraybackslash}p{\dimexpr 0.5\linewidth-\tabcolsep}@{}}
  \lipsum[1][1] & \lipsum[1][2]
\end{tabular}

\noindent
\begin{tabularx}{\linewidth}{@{}>{\raggedright\arraybackslash}X>{\raggedleft\arraybackslash}X@{}}
  \lipsum[1][1] & \lipsum[1][2]
\end{tabularx}



\end{document}

You must log in to answer this question.

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