2

I have a document that is split into two columns of different width. In one of the two columns, I would like to add a table that is large exactly as the width of that column. Is there an automatic way to set the table width exactly as the column width where it appears?

In the following example I use paracol to split the document into two columns. In particular, I set the width of the left column as \columnratio{0.6}. Now, instead of writing \begin{tabularx}{0.4\textwidth}{|X|X|X|} for the width of the table in the right column, is there an automatic way (like a way to assign the variable "width") to the table? Something like \begin{tabularx}{{1-\columnratio{0.6}}\textwidth}{|X|X|X|}?

\documentclass{article}
\usepackage[a4paper,margin=0.1cm]{geometry}
\usepackage{paracol}
\usepackage{lipsum}
\usepackage{tabularx}

\begin{document}

\columnratio{0.6} \begin{paracol}{2} \lipsum[1] \switchcolumn \lipsum[1] \ \begin{tabularx}{0.395\textwidth}{|X|X|X|} \hline item 11 & item 12 & item 13 \ \hline item 21 & item 22 & item 23 \ \hline \end{tabularx} \end{paracol}

\end{document}

enter image description here

Ommo
  • 835
  • 1
    Did you try \begin{tabularx}{\columnwidth}{|X|X|X|}? – samcarter_is_at_topanswers.xyz Mar 07 '24 at 14:45
  • Issue solved, thanks a lot! If you put it in an Answer, I accept it :-) Thanks a lot! – Ommo Mar 07 '24 at 14:48
  • 1
    Please see the answer I've posted in the meantime (which I wrote before seeing @samcarter_is_at_topanswers.xyz's comment). – Mico Mar 07 '24 at 14:49
  • 1
  • Oh gosh, you guys are very fast in replying! :-) Thanks a lot to both of you! – Ommo Mar 07 '24 at 14:51
  • @samcarter_is_at_topanswers.xyz, I have just seen that answer, thanks to your comment. I did not know about (i) \columnwidth and (ii) the possibility to use \columnwidth within a two-column framework. Therefore, I think I could not be able to find that answer in regard to my problem. If you think this is a duplicate question, I will delete it, or please go ahead. Thanks again! :-) – Ommo Mar 07 '24 at 14:55
  • 2
    @Ommo No need to delete your question. Adding a duplicate just means that future users with the same problem will find additional reading material about the topic. – samcarter_is_at_topanswers.xyz Mar 07 '24 at 14:57
  • Ah ok, I did not know, thanks! ...However, I have just seen that someone suggested to close this question.. Maybe a moderator, I do not know.. :-) – Ommo Mar 07 '24 at 14:59

1 Answers1

2

I suggest you change 0.395\textwidth to \columnwidth. (\linewidth works too.)

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1mm]{geometry}
\usepackage{paracol,lipsum,tabularx}

\begin{document}

\columnratio{0.6} \begin{paracol}{2} \lipsum[1] \switchcolumn \lipsum[1]

\noindent
\begin{tabularx}{\columnwidth}{|X|X|X|}
   \hline 
   item 11 & item 12 & item 13 \\
   \hline 
   item 21 & item 22 & item 23 \\
   \hline
\end{tabularx}

\end{paracol}

\end{document}

Mico
  • 506,678