Search code examples
latexmulticol

Vertical align in table on Latex


I want to make a table and print the text in the middle of all cases. I use the array package and I wrote:

\begin{table}[H]
\begin{center}
\begin{tabular}{|m{3cm}|m{2.5cm}|m{2.5cm}|m{2.5cm}|m{6cm}|}

But then Latex says that I missed one '$' or one '{' in my table... but there is only text, so I don't understand. When I switched to :

\begin{table}[H]
\begin{center}
\begin{tabular}{|m{3cm}|C{2.5cm}|C{2.5cm}|C{2.5cm}|C{6cm}|}

all is ok and works... but it's ugly. I read a lot of stuff about that on the site already but never fixed my obvious-like problem :/


Solution

  • Here is a minimal example of the layout I use for tables. Different combinations of sizing and formatting are shown. I am not sure if this is what you asked for. Please reformulate your question, if it is not.

    \documentclass{scrartcl}
    
    \usepackage{booktabs} % \cmidrule in tables
    % \usepackage{caption}  % Nice Captions
    % \usepackage{longtable} % Tables larger than one page
    % \usepackage{multirow} % Mergings Cells
    % \usepackage{multicol} % Merging Cells
    \usepackage{tabularx}
    
    \begin{document}
    \begin{table}
      \caption{Some caption, for tables always above}
      \label{some label}
      \begin{tabularx}{0.99\textwidth}{>{\centering}X>{\raggedleft}X>{\raggedleft}X>{\raggedleft}p{0.5cm}>{\raggedleft}p{3cm}>{\raggedright}X>{\raggedleft\arraybackslash}X}
        \toprule
        \textsc{Foobar} & $a$ & $b$ & $c$ & $d$ & $e$ & $f$ \\
        \cmidrule(r){1-1} \cmidrule(lr){2-2} \cmidrule(lr){3-3} \cmidrule(lr){4-4} \cmidrule(lr){5-5} \cmidrule(lr){6-6} \cmidrule(l){7-7}
        1               & 2   & 2   & 2   & 2   & 2   & 2   \\
        2               & 4   & 5   & 4   & 4   & 4   & 4   \\
        3               & 4   & 3   & 4   & 3   & 3   & 3   \\
        \bottomrule
      \end{tabularx}
    \end{table}
    \end{document}
    

    PDF