0

I am in a situation in which it seems desirable to use multiple tabularx environments to feign a single one. But I would like for the contents of their right-most columns to be flush left with each other. That is, is there a way to adjust the code below so that, of the words 'Yessir,' 'Yessirino,' and 'Ya-huh,' the one with the greatest width (namely 'Yessirino') is automatically chosen to establish a common width for the right-most column in each of the three tabularx environments?

\documentclass{article}
\usepackage{tabularx}
\usepackage{showframe}

\begin{document}

\centering

\begin{tabularx}{\linewidth}{r >$r<$ @{} >{\raggedright${}}X<{$} l}

Yes & Yes & Yes & Yessir

\end{tabularx}

\begin{tabularx}{\linewidth}{r >$r<$ @{} >{\raggedright${}}X<{$} l}

Yes & Yes & Yes & Yessirino

\end{tabularx}

\begin{tabularx}{\linewidth}{r >$r<$ @{} >{\raggedright${}}X<{$} l}

Yes & Yes & Yes & Ya-huh

\end{tabularx}

\end{document}

(Note: If you would like a partial explanation as to why I would like to use multiple tabularx environments to feign a single one, see David Carlisle's answer to a previous question of mine at https://tex.stackexchange.com/a/693585/277990. This, however, is probably not essential to my question.)

Noah J
  • 515

1 Answers1

1

Do you after the following:

enter image description here

Vertical line before last column is added that it is better visible equal width of last columns in all tables. In the real document you can remove it.

\documentclass{article}
\usepackage{tabularx}
\newlength\colwidth
\usepackage{showframe}

\begin{document}

\begingroup

\centering \settowidth\colwidth{Yessirino} % <--- select the longest text in the last columns \begin{tabularx}{\linewidth}{r >{$}r<{$} @{} >{\raggedright${}}X<{$} | p{\colwidth}} Yes & Yes & Yes & Yessir \end{tabularx}

\begin{tabularx}{\linewidth}{r >{$}r<{$} @{} >{\raggedright${}}X<{$} | p{\colwidth}} Yes & Yes & Yes & Yessirino \end{tabularx}

\begin{tabularx}{\linewidth}{r >{$}r<{$} @{} >{\raggedright${}}X<{$} | p{\colwidth}} Yes & Yes & Yes & Ya-huh \end{tabularx} \endgroup

\end{document}

Zarko
  • 296,517
  • Is there a reason for \begingroup and \endgroup? If I get rid of them the output does not change. – Noah J Aug 21 '23 at 16:33
  • 1
    @NoahJ, by group I limit setting the \colwidth to those tables only (and by this enable to make a different settings for another tables, if needed). If in your document this is not a case, you remove it. – Zarko Aug 21 '23 at 18:15