3

I'm trying to insert a list in a multicolumn of a table defined through tabularx:

\documentclass[11pt, a4paper]{standalone}
\usepackage{tabularx}
\usepackage[left=25mm, right=25mm, top=25mm, bottom=25mm]{geometry}

\begin{document}
\begin{tabularx}{\textwidth}{>{\hsize=1.5\hsize}X >{\raggedleft\arraybackslash\hsize=0.5\hsize}X}
  Lorem ipsum dolor & sit amet \\
  consectetur adipiscing elit & \\
  \multicolumn{2}{>{\hsize=2\hsize}X}
  {
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis dui eu velit tincidunt feugiat at ac magna.
    \begin{itemize}
      \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis dui eu velit tincidunt feugiat at ac magna.
    \end{itemize}
  } \\
\end{tabularx}
\end{document}

That's what I get using pdflatex:

test

How can I make the list as wide as the text inside the multicolumn?

3

Here's a solution that (a) uses \noindent before the start of the tabularx environment, (b) uses @{} directives to eliminate the (presumably unwanted) vertical whitespace to the left of the first column and the right of the final column, and (c) uses \multicolumn{2}{@{}p{\textwidth}@{}} instead of \multicolumn{2}{>{\hsize=2\hsize}X}. Observe that nothing bad happens if you use the \multicolumn{2}{...} instruction in the manner suggested here and that it's not necessary to load the enumitem package.

As mentioned above, the @{} items at the start and end of the second argument of the tabularx environment and in the second argument of \multicolumn serve to suppress the vertical whitespace (with a width of \tabcolsep) that would otherwise be inserted. If you do want this whitespace, leave off the @{} items and change the width of the p column from \textwidth to \textwidth-2\tabcolsep.

(The thin black lines in the screen shot denote the edges of the text block.)

enter image description here

\documentclass[11pt, a4paper]{article}
\usepackage{tabularx}
\usepackage[margin=25mm,showframe]{geometry}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{}
       >{\hsize=1.5\hsize}X 
       >{\raggedleft\arraybackslash\hsize=0.5\hsize}X @{}}
  Lorem ipsum dolor & sit amet \\
  consectetur adipiscing elit & \\
  \multicolumn{2}{@{}p{\textwidth}@{}}
  {
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis dui eu velit tincidunt feugiat at ac magna.
    \begin{itemize}
      \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis dui eu velit tincidunt feugiat at ac magna.
    \end{itemize}
  } \\
\end{tabularx}
\end{document}
  • @Mico, your initial guess was right. Thank you for the solution without parbox and minipage. I knew it had to exist. – martemiev Nov 4 '14 at 19:55
3

1. Tabularx

First the warning from subsection 4.3 last bullet in the tabularx-manual:

  • Do not use \multicolumn entries which cross any X column.

To line up the text in the left margin, a simple solution is to load the package enumitem and use a local, optional value let the bullet flush the left margin [leftmargin=*].

To achieve your goal number two, I recommend Mico's solution in his answer below. Another solution is to set the text in the spanned columns in a parboxof same with as the spanned columns, i.e. the width of the table minus the distance between the columns, which is (\textwidth - 2\tabcolsep). I have loaded the calc package to perform the calculation. To enclose the list in a parbox may solve some spacing issue you may encounter when you use lists in tables, see for example this answer and its links.

As you will see, all text now line up at the right margin.

\documentclass[11pt, a4paper]{standalone}
\usepackage{tabularx,enumitem,calc}
\usepackage[left=25mm, right=25mm, top=25mm, bottom=25mm]{geometry}

\begin{document}
\noindent\begin{tabularx}{\textwidth}
         {>{\hsize=1.5\hsize}X
          >{\raggedleft\arraybackslash\hsize=0.5\hsize}X}
  Lorem ipsum dolor & sit amet \\
  consectetur adipiscing elit & \\
  \multicolumn{2}{>{\hsize=2\hsize}X}
  {\parbox{\textwidth-2\tabcolsep}
          {Lorem ipsum dolor sit amet, consectetur adipiscing
          elit. Quisque quis dui eu velit tincidunt feugiat
          at ac magna.  
          \begin{itemize}[topsep=0pt,leftmargin=*]
            \item Lorem ipsum dolor sit amet, consectetur
                  adipiscing elit. Quisque quis dui eu velit
                  tincidunt feugiat at ac magna.
            \end{itemize}}%
      }
\end{tabularx}
\end{document}

If you have more than one list in the table, you may set the whole table in a local environment (enclose the table in curly brackets {} and have the optional agreement just after the first bracket, i.e.:

\setitemize{topmargin=0pt, leftmargin=*}

Or: If you will have the setup in all list in your document, put the setitemize-command in the preamble of your document.

Figure-1

2. Tabular

You may also try to use the ordinary tabular-environment (you need to load the array package).

When I analysed your MWE, it seems that it is the relation between column one and two, which trigger your use of tabularx. A slightly simpler solution might be to use two p-columns.

\documentclass[11pt, a4paper]{standalone}
\usepackage{tabularx,enumitem,calc}
\usepackage[left=25mm, right=25mm, top=25mm, bottom=25mm]{geometry}

\begin{document}

\noindent\begin{tabular}
               {p{0.75\linewidth-2\tabcolsep}
                >{\raggedleft\arraybackslash}p{0.25\textwidth-2\tabcolsep}}
               Lorem ipsum dolor & sit amet \\
               consectetur adipiscing elit & \\
               \multicolumn{2}{l}
               {\parbox{\textwidth-2\tabcolsep}
                       {Lorem ipsum dolor sit amet, consectetur
                       adipiscing elit. Quisque quis dui eu velit
                       tincidunt feugiat at ac magna. 
                       \begin{itemize}[topsep=0pt,itemsep=0pt, leftmargin=*]
                         \item Lorem ipsum dolor sit amet, consectetur 
                               adipiscing elit. Quisque quis dui eu
                               velit tincidunt feugiat at ac magna.
                         \item Lorem ipsum dolor sit amet, consectetur 
                               adipiscing elit. Quisque quis dui eu
                               velit tincidunt feugiat at ac magna.
                         \item Lorem ipsum dolor sit amet, consectetur
                               adipiscing elit. Quisque quis dui eu
                               velit tincidunt feugiat at ac magna.
                         \item Lorem ipsum dolor sit amet, consectetur
                               adipiscing elit. Quisque quis dui eu
                               velit tincidunt feugiat at ac magna.\strut
                       \end{itemize}
       }}
\end{tabular}
\end{document}

enter image description here

I have corrected the errors in my examples as suggested by Mico, to avoid the table to protrude into the right margins. The \noindentis not always necessary, f.ex. after a sectioning command. A better solution is to use Mico's p{\linewidth eventually reduced with -2\tabcolsep} if you do not use @{}to reduce the left and right space.

  • Thank you for the answer, but the goal was to spread the text in the list on two columns of the table. Unfortunately, I still can't figure out how to do that using your code, and use minipage as a workaround. – martemiev Nov 3 '14 at 18:10
  • thank you for the updated answer. Both parbox and minipage have the same complexity for me, so I don't have a preference between them. Anyway, your computation of the width of the parbox gave an insight to me. – martemiev Nov 4 '14 at 14:49
  • @martemiev Even though you have accepted my answer, I have to direct you to Mico's answer below, which actually solve your problems. – Sveinung Nov 4 '14 at 20:21
  • then I'll accept Mico's answer, if you don't mind, to direct other users with similar questions to the preferred solution. – martemiev Nov 5 '14 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.