1

I am learning Tex. I am trying to span an unordered list across 2 columns, but it doesn't work, and I can't figure out the problem. It works fine for a regular string of text. Here is the sample code that I can't get working:

\documentclass[12pt,a4paper]{article}

\usepackage{enumitem}
\usepackage{tabularx}

\begin{document}
  \begin{tabularx}{\linewidth}{|X|X|}
    \hline
    Col 1 & Col 2\\
    \hline
    \multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}{A long sentence that successfully spans across 2 cols.}\\
    \hline
    \multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}{
    \begin{itemize}
      \item An item in Itemize that should span across 2 cols.
      \item Another item in Itemize that should also span across 2 cols.
    \end{itemize}}\\
    \hline
  \end{tabularx}
\end{document}

Would appreciate any help!

2
  • Welcome to TeX SX! For me, it works. Do you have any error message? Or warning?
    – Bernard
    Commented Feb 21, 2022 at 15:08
  • @Bernard, I had 2 warnings: ``` Underfull \hbox (badness 5787) in paragraph at lines 19--19 Overfull \hbox (17.62482pt too wide) in paragraph at lines 19--20 ``` but I don't think these are related to the problem that I had. David's answer below solved my problem. Strange that it worked for you as-is. Would this have to do with the version of tabularx or TeX I am using (TeX Live 2021)?
    – fishfin
    Commented Feb 22, 2022 at 2:51

1 Answer 1

2

You need to set \linewidth as well (the manual probably ought to mention that)

enter image description here

\documentclass[12pt,a4paper]{article}

\usepackage{enumitem}
\usepackage{tabularx}

\begin{document}
  \begin{tabularx}{\linewidth}{|X|X|}
    \hline
    Col 1 & Col 2\\
    \hline
    \multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}{A long sentence that successfully spans across 2 cols.}\\
    \hline
    \multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\linewidth=\hsize}X|}{
    \begin{itemize}
      \item An item in Itemize that should span across 2 cols.
      \item Another item in Itemize that should also span across 2 cols.
    \end{itemize}}\\
    \hline
  \end{tabularx}
\end{document}
4
  • Thank you @David, this worked. However, I didn't understand why I didn't have to do it for the normal text, but had to for the itemize.
    – fishfin
    Commented Feb 22, 2022 at 3:02
  • @fishfin linebreaking is a tex primitive operation that only looks at \hsize latex maintains several lengths to control nested lists and indentation so an itemize within a quote within an enumerate knows how long the margins and text blocks are supposed to be, the main one of these is \linewidth that gets set in a p (so X) column to mach \hsize but if you change hsize and have a laetx display you should change \linewidth as well Commented Feb 22, 2022 at 7:42
  • Ok, so since \hsize is a primitive, changing that does not trigger change of \linewidth automatically, so the LaTeX engine continues to think it has smaller width. By manually forcing this change to \linewidth, it worked. So now I was wondering instead of \hsize=2\hsize+2\..., I could have directly done \linesize=2\hsize+2\..., but since I don't know much about internals of the \hsize primitive, for now I think I understand both \hsize and \linewidth need to be in sync. Thank you once again @David!
    – fishfin
    Commented Feb 22, 2022 at 12:24
  • @fishfin no you need to set them both. \setlength or just \hsize=... or \linewidth=... is a very low level register assignmnt it just does the assignment specified and nothing else. Commented Feb 22, 2022 at 12:36

You must log in to answer this question.

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