Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I made a table like this one

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
  \begin{document}
    \begin{table}[htb]
        \centering
        \caption{Reproduzierbarkeit der Elektroden}
        \begin{tabular}{ccccc|c|c|c|c|}
            \toprule
                \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\  
            \midrule
                &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
            \cmidrule[0.5pt]{2-9}
                 6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
            \bottomrule
            \label{tab:reproduzierbarkeit}
        \end{tabular} 
    \end{table}
  \end{document}

and what I get is:

enter image description here

So why is the width of the ninth column bigger than the others, although all rows are centered? How can I change this, so that each column has the same width?

Thanks!

share|improve this question
    
Do you mean the width of the last column? It's because of the \multicolumn above I'd think, it is wider than the four columns below, so additional width is added to the last column. (Edit: rows are horizontal, columns are vertical.) –  Torbjørn T. Mar 16 at 19:21
    
Oh sorry, I changed it. Yes I mean the width. How can I fix it, that they are equal? –  user47091 Mar 16 at 19:33
    
It is basically the same problem as tex.stackexchange.com/questions/128736/… I think, you could try using Mico's suggestion. –  Torbjørn T. Mar 16 at 19:48
    
@TorbjørnT. I think you can do it without tabularx and without needing to know the overall width of the tabular. Does my deleted-edited-undeleted answer do what's wanted here? (I'm not sure if it is quite right...) –  cfr Mar 16 at 19:59

2 Answers 2

up vote 2 down vote accepted

You need to make sure that the spanned cells are wider than the multicolumn entry.

enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
  \begin{document}
    \begin{table}[htb]
        \centering
        \newcommand\x{\makebox[1pt]{}}
        \caption{Reproduzierbarkeit der Elektroden}
        \begin{tabular}{@{}c*4{>\x c<\x}|*4{>\x c<\x|}@{}}
            \toprule
                \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\  
            \midrule
                &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
            \cmidrule[0.5pt]{2-9}
                 6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
            \bottomrule
            \label{tab:reproduzierbarkeit}
        \end{tabular} 
    \end{table}
  \end{document}
share|improve this answer
    
@TorbjørnT. thanks, fixed and image updated:-) –  David Carlisle Mar 16 at 20:45

You could do this. I don't know which ones exactly you want equal in width. This makes the final four columns of equal width using a new column type, H:

\documentclass{article}
\usepackage{array,calc}
\newlength{\origtabcolsep}
\setlength{\origtabcolsep}{\tabcolsep}
\newlength{\mycolswidth}
\settowidth{\mycolswidth}{\textbf{maximale Abweichung [\%]}}
\newlength{\mycolwidth}
\setlength{\mycolwidth}{.25\mycolswidth-.75\tabcolsep}
\newcolumntype{H}{>{\centering\arraybackslash}p{\mycolwidth}|}
\usepackage{booktabs}
\begin{document}
  \begin{table}[htb]
      \centering
      \caption{Reproduzierbarkeit der Elektroden}
      \setlength{\tabcolsep}{.75\origtabcolsep}
      \begin{tabular}{*{5}{c}|*{4}{H}}
          \toprule
              \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\
          \midrule
              &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
          \cmidrule[0.5pt]{2-9}
               6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
          \bottomrule
          \label{tab:reproduzierbarkeit}
      \end{tabular}
  \end{table}
\end{document}

Tabular using new column type, H, for final 4 columns

share|improve this answer
    
That looks better, though the table is a bit wider than \textwidth, leading to an overfull box. (Sorry for being difficult to please.) Oh, and if you add \arraybackslash after \centering in the definition of H you can use \\ to start new table rows. –  Torbjørn T. Mar 16 at 20:00
    
@TorbjørnT. Yes. I think it should be \tabcolsep rather than \arraycolsep. That helps a bit but I think there's some other spacing there I'm not getting. Thanks for pointing out \arraybackslash - that's a command I didn't even know to look for. –  cfr Mar 16 at 20:10
    
@TorbjørnT. This version seems to avoid that at the cost of squeezing the tabular slightly. The overfull box is caused by the combination of array and the vertical lines since array allows them their natural width... –  cfr Mar 16 at 20:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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