2

I'm trying to get my cells in a tabular environment horizontally and vertically centered. MWE to be found at the end.

I tried different orientations: Which does what it is supposed to, as well as m{4cm} up to complex variations like {\centering}m{4cm}} or {\centering\arraybackslash}m{4cm}}, although I must be honest about not knowing what exactly the arraybackslash parameter is supposed to change - I just copied that one from another stackexchange posting.

All texts, including the vertically written one, are supposed to be horizontally and vertically centered. The main part of the table will be pictures with a caption each, the pictures being square. If anybody can tell me how to align the cells, I guess that should work for the cells including pictures as well, does it?

Edit: Updated the code and took a screenshot of the result. \parbox is used as a placeholder to make a higher cell. The 1,5 stays centered, that is true. Yet, the other text parts seem to be a little off to the top, maybe because of the comma going below the baseline (is that the right word for it?)? Any way of how to lower the overall writing a pt or two? And any way to get the cells to be a tiny bit higher? in the "foobar foobar" cell, the writing scratches the lines at top and bottom. Also, the verticalized text is off-center. Would I have to work with minipages to get that centered?

enter image description here

\documentclass{scrreprt}
\usepackage{array}
\usepackage{multirow}
\usepackage{rotating}
\begin{document}

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
    \hline
    \multicolumn{2}{|c|}{} & \multicolumn{5}{c|}{foo}\\
    \cline{3-7}
    \multicolumn{2}{|c|}{}  & 1,0 & 2,0 & 3,0 & 4,0 & 5,0\\
    \hline
    \multirow{5}{*}{\rotatebox{90}{bar}} & 1,0 & & & & & \\
    \cline{2-7}
     & 1,5 & \parbox{2cm}{foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar } & & & & \\
    \cline{2-7}
     & 2,0 & & & & & \\
    \cline{2-7}
     & 2,5 & & & & & \\
    \cline{2-7}
     & 3,0 & & & & & \\
    \hline
    \end{tabular}
\end{table}

\end{document}
  • All cells of your table are centred, except perhaps the multirow which can accept a minor adjustment. The problem of pictures is different. – Bernard Mar 22 '16 at 19:52
  • Bernard, I updated the problem, might I ask you to look at it again? Also, I'll add the pictures tomorrow or thursday, I hope that won't cause any further problems. – firefrog Mar 23 '16 at 1:22
1

You could create a new column type like

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

and then use C{<your width>} as column definition, setting <your width> as you like. This way you'll have your columns vertically and horizontally centered.

I also suggest to remove vertical lines, avoid rotated cells and use booktabs.

\documentclass{scrreprt}
\usepackage{array}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{booktabs}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
    \chapter{A chapter}
    Table \ref{tab:yours} is your table, but I suggest to you to redesign your
    table like \ref{tab:mine}.
    \begin{table}
        \centering\setlength\extrarowheight{2pt}
        \caption{Your table\label{tab:yours}}
        \begin{tabular}{|*2{C{.5cm}|}*5{C{2cm}|}}
            \hline
            \multicolumn{2}{|c|}{} & \multicolumn{5}{c|}{foo}\\
            \cline{3-7}
            \multicolumn{2}{|c|}{} & 1,0 & 2,0 & 3,0 & 4,0 & 5,0\\
            \hline
            & 1,0 & & & & & \\
            \cline{2-7}
            \multirow{4}{*}{\rotatebox[origin=c]{90}{bar}} & 1,5 & foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar & & & & \\
            \cline{2-7}
            & 2,0 & & & & & \\
            \cline{2-7}
            & 2,5 & & & & & \\
            \cline{2-7}
            & 3,0 & & & & & \\
            \hline
        \end{tabular}
    \end{table}
    \begin{table}
        \centering\setlength\extrarowheight{2pt}
        \caption{My suggestion\label{tab:mine}}
        \begin{tabular}{C{.7cm}*5{C{2cm}}}
            \toprule
            & \multicolumn{5}{c}{foo}\\
            \cmidrule(l){2-6}
            bar & 1,0 & 2,0 & 3,0 & 4,0 & 5,0\\
            \midrule
            1,0 & & & & & \\
            \midrule
            1,5 & foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar & & & & \\
            \midrule
            2,0 & & & & & \\
            \midrule
            2,5 & & & & & \\
            \midrule
            3,0 & & & & & \\
            \toprule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

enter image description here

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.