LaTeX forum ⇒ Graphics, Figures & TablesCenter align lists in cells

Information and discussion about graphics, figures & tables in LaTeX documents.
bstex
Posts: 65
Joined: Mon Oct 23, 2017 10:22 am

Center align lists in cells

Postby bstex » Fri Jan 19, 2018 8:23 pm

Hi,
I'm trying to center align the lists inside the cells of a table.
Till now, I have this:
  1. \documentclass[a4paper]{book}
  2. \usepackage{array}
  3. \usepackage{enumitem}
  4. \begin{document}
  5.  
  6. \begin{table}[h]
  7. \centering
  8. \begin{tabular}{|>{\centering\arraybackslash} m{10em}|>{\centering\arraybackslash} m{8em}|>{\centering\arraybackslash} m{9em}|}
  9. \multicolumn{1}{|c|}{A} & \multicolumn{1}{c|}{B} & \multicolumn{1}{c|}{C} \\
  10.  
  11. \begin{enumerate}
  12. \item [A.] text
  13. \item [D.] text
  14. \item [E.] text
  15. \end{enumerate}
  16. &
  17. \begin{enumerate}[label=\textbf{\arabic*.}]
  18. \item text
  19. \item text
  20. \item text
  21. \end{enumerate}
  22. &
  23. \begin{enumerate}
  24. \item [B -] text
  25. \item [C -] text
  26. \item [F -] text
  27. \end{enumerate}
  28. \end{tabular}
  29. \end{table}
  30.  
  31. \end{document}

which produces this:
Screen Shot 2018-01-19 at 20.20.41.png
Screen Shot 2018-01-19 at 20.20.41.png (17.14 KiB) Viewed 539 times


Why lists don't cooperate with the center-align? Any help?

Also, a general question about tables:
Is there any way to remove the space which appears under the last row of the table? It always seems like there is an extra empty row under the last text.

Thank you.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8954
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jan 19, 2018 10:00 pm

Hi,

\centering within the enumerate environment works:

\begin{enumerate}\centering ...

It seems like there is an extra line because there's a space before and after enumerate lists. enumerate is for numbered lists, but is not designed for using in table cells.

Stefan
Site admin

bstex
Posts: 65
Joined: Mon Oct 23, 2017 10:22 am

Postby bstex » Fri Jan 19, 2018 10:14 pm

I must have been misunderstood. Sorry, my fault.
I need the lists to be as they are right now (left-aligned), but the whole list to be placed in the center of the cell.
I mean something like this:
Screen Shot 2018-01-19 at 22.11.08.png
Screen Shot 2018-01-19 at 22.11.08.png (19.01 KiB) Viewed 532 times


Thank you, Stefan!

bstex
Posts: 65
Joined: Mon Oct 23, 2017 10:22 am

Postby bstex » Fri Jan 19, 2018 10:24 pm

Since you told me about the enumerate conflict with tables, I will remove the enumerate and insert the text as a plain text and not as a list.
Thank you again.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8954
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jan 19, 2018 10:30 pm

A not so easy workaround: putting the enumerate in a minipage or use \parbox, estimate the width, or calculate it, such as:

  1. \usepackage{varwidth}
  2. \newlength\lenA
  3. \newsavebox\boxA
  4. \savebox\boxA{\begin{varwidth}{\textwidth}[A.]\qquad text text\end{varwidth}}
  5. \setlength\lenA{\the\wd\boxA}
  6. % above goes to the preamble
  7. ...
  8. %in the table cell:
  9. \parbox{\lenA}{%
  10. \begin{enumerate}
  11. \item [A.] text text
  12. \item [D.] text
  13. \item [E.] text
  14. \end{enumerate}}
  15. ...


Complete code for testing:

  1. \documentclass[a4paper]{book}
  2. \usepackage{array}
  3. \usepackage{enumitem}
  4.  
  5. \usepackage{varwidth}
  6. \newlength\lenA
  7. \newsavebox\boxA
  8. \savebox\boxA{\begin{varwidth}{\textwidth}[A.]\qquad text text\end{varwidth}}
  9. \setlength\lenA{\the\wd\boxA}
  10.  
  11. \begin{document}
  12.  
  13. \begin{table}[h]
  14. \centering
  15. \begin{tabular}{|>{\centering\arraybackslash} m{10em}|>{\centering\arraybackslash} m{8em}|>{\centering\arraybackslash} m{9em}|}
  16. \multicolumn{1}{|c|}{A} & \multicolumn{1}{c|}{B} & \multicolumn{1}{c|}{C} \\
  17.  
  18. \parbox{\lenA}{%
  19. \begin{enumerate}
  20. \item [A.] text text
  21. \item [D.] text
  22. \item [E.] text
  23. \end{enumerate}}
  24. &
  25. \begin{enumerate}[label=\textbf{\arabic*.}]
  26. \item text
  27. \item text
  28. \item text
  29. \end{enumerate}%
  30. &
  31. \begin{enumerate}
  32. \item [B -] text
  33. \item [C -] text
  34. \item [F -] text
  35. \end{enumerate}%
  36. \end{tabular}
  37. \end{table}
  38.  
  39. \end{document}


But yes, simple text would be much easier.

Stefan
Site admin

bstex
Posts: 65
Joined: Mon Oct 23, 2017 10:22 am

Postby bstex » Fri Jan 19, 2018 10:32 pm

Thanks.
I'll give a shot that solution too. ;)


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 8 guests