1

I've read a lot about vertical centering in tabularx-tables and found a general solution. However, when having multiple lines in cells, the margins seem to be off.

Your can see that in the right-most cell of the top row there is no margin at the bottom. Furthermore, in the second row, the circles do not seem to be aligned perfectly in the middle, while it looks good in the third row.

I would appreciate any ideas on how to fix this!

enter image description here

\documentclass[a4paper,10pt,BCOR10mm,oneside,headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym}
\usepackage{enumitem}
\usepackage{color}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}    % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\setlength{\extrarowheight}{0.35cm}

\newcommand{\QO}{\huge{\textbf{$\Circle$}}\small}

\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cX*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} & \textbf{A very very very super long question, that is going to be split for sure\dots \newline (Something else)}
   & short & longer & little longer & super-duper mega very very very long \\[1em]%
   & short & \QO & \QO & \QO & \QO\\[1em]
   & Very long, will most propably span multiple lines. Might even mess up the formatting a little bit\dots & \QO & \QO & \QO & \QO\\[1em]
\end{tabularx}

\end{document}
1
  • \newcommand{\QO}{\huge{\textbf{$\Circle$}}\small} makes all following text small, is that intended? – David Carlisle Mar 10 '19 at 0:02
0

Here is a solution with the cellspace package, which defines minimal vertical padding at the top and bottom of cells in columns with specifier prefixed by the letter S. I took the opportunity to simplify the definition of \QO.

\documentclass[a4paper,10pt,BCOR10mm,oneside,headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym, amssymb, amsfonts, bm}
\usepackage{enumitem}
\usepackage{color}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor} % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}
\newcolumntype{P}[1]{>{\centering\arraybackslash}S{m{#1}}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\newcommand{\QO}{\textbf{\huge\Circle}}

\usepackage{cellspace}
\setlength{\cellspacetoplimit}{2ex}
\setlength{\cellspacebottomlimit}{2ex}
\addparagraphcolumntypes{X}

\begin{document}

\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cS{X}*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} & \textbf{A very very very super long question, that is going to be split for sure\dots \newline (Something else)}
   & short & longer & little longer & super-duper mega very very very long \\
   & short & \QO & \QO & \QO & \QO \\
   & Very long, will most probably span multiple lines. Might even mess up the formatting a little bit\dots & \QO & \QO & \QO & \QO\\
\end{tabularx}

\end{document} 

enter image description here

2

The circle definition affects surrounding text

\newcommand{\QO}{\textbf{\huge$\Circle$}}

would be a better definition but it is clearer if you do

\newcommand{\QO}{!\dotfill\textbf{\huge$\Circle$}\dotfill!}

enter image description here

Here you can see that the .... baseline aligns with the baseline of Short, but as most of the circle is above the baseline it appears higher in the cell.

1

As David Carlisle has pointed out in his answer, your definition of \QO places the circle on the (typographic) baseline. Because its size is huge (literally: \huge), it ends up looking like it's been shifted upward quite a bit. A remedy is to center the center vertically on the math axis. (To visualize the height of the the math axis: the math symbols - and + are placed on this axis.)

enter image description here

The preceding image was generated by

ABC\dots$\bm\Circle$\dots\QOa\dots$-$\QOb$-$\dots XYZ

where

\newcommand{\QOa}{\textbf{\huge$\Circle$}} % OP's definition, improved
\newcommand{\QOb}{$\vcenter{\hbox{\huge$\bm\Circle$}}$} % proposed new def.

Anyway, if one places the circles on the math line, the table looks fine (to my eyes at least).

enter image description here

\documentclass[paper=a4,  fontsize=10pt,
               BCOR=10mm, twoside=false, 
               headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym} % for "\Circle" macro
\usepackage{enumitem}
%%\usepackage{color} % don't load both 'color' and 'xcolor'
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}    % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}

\usepackage{bm} % for "\bm" macro
%% center the circle (vertically) on the math axis:
\newcommand{\QO}{$\vcenter{\hbox{\huge$\bm\Circle$}}$}

\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\setlength{\extrarowheight}{0.35cm}

\begin{document}

\noindent % <-- don't forget this instruction
\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cX*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} 
   & \textbf{A very very very super long question, that is 
     going to be split for sure\dots   
   \newline (Something else)}
   & short & longer & little longer 
   & super-duper mega very very very long \\[1em]%
   & short & \QO & \QO & \QO & \QO\\[1em]
   & Very long, will most propably span multiple lines. 
     Might even mess up the formatting a little bit\dots 
           & \QO & \QO & \QO & \QO\\[1em]
\end{tabularx}

\end{document}

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.