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 have the following table in my document, and it seems to be OK except that the topmost columns' text is not centered. I can't figure out why not. I could manually adjust the multicolumn m sizes to get there, but that does not seem like the right solution.

I have a similar table in my document and the centering works fine. This is all within a 2 column IEEE-type document. I thought maybe my table was too wide and something weird was happening - but making the table less wide does not solve the problem (although it does make the text off center in different ways). My entire table is centered on the page; I tried taking that out and leaving it left justified and that had no effect.

messed up table

The TeX that generates this table is:

\begin{table*}
   \centering
   \caption{Results on Xilinx Virtex 5 Devices}
   \label{tab:XilinxResults}
   \begin{tabular}{|m{3cm}|m{1.50cm}|m{1.50cm}|m{1.30cm}|m{1.30cm}|m{1.30cm}|m{1.30cm}|m{1.30cm}|m{1.30cm}|}
      \cline{2-9}
      \multicolumn{1}{>{\centering}m{3.0cm}|}{ } &  % blank box
      \multicolumn{2}{>{\centering}m{3.0cm}|}{\bfseries Clock Frequency (MHz)} &
      \multicolumn{2}{>{\centering}m{2.6cm}|}{\bfseries Throughput (Mbit/s)} &
      \multicolumn{2}{>{\centering}m{2.6cm}|}{\bfseries Area (CLB Slices)} &
      \multicolumn{2}{>{\centering}m{2.6cm}|}{\bfseries Throughput / Area} \tabularnewline \hline
      \multicolumn{1}{|>{\centering}m{3cm}|}{\bfseries Architecture} &
      \multicolumn{1}{>{\centering}m{1.50cm}|}{\bfseries 512-bit} &
      \multicolumn{1}{>{\centering}m{1.50cm}|}{\bfseries 256-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 512-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 256-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 512-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 256-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 512-bit} &
      \multicolumn{1}{>{\centering}m{1.30cm}|}{\bfseries 256-bit}
      \tabularnewline\hline\hline

      \bfseries BMW x1 &
      \raggedleft 4.89 & \raggedleft 8.14 & \raggedleft 5004  & \raggedleft 4168 &
      \raggedleft 12039 & \raggedleft 6164 & \raggedleft 0.42 & \raggedleft 0.68 \tabularnewline \hline
      \bfseries BMW x1-PPL18 &
      \raggedleft 46.51 & \raggedleft 70.97 & \raggedleft 47628  & \raggedleft 36335 &
      \raggedleft 24564 & \raggedleft 11610 & \raggedleft 1.84 & \raggedleft 2.96 \tabularnewline \hline
      \bfseries BMW /32(h) &                                                                                    
      \raggedleft 44.27 & \raggedleft 69.41 & \raggedleft 1416  & \raggedleft 1110 &                            
      \raggedleft 4001 & \raggedleft 2211 & \raggedleft 0.35 & \raggedleft 0.50 \tabularnewline \hline          
      \bfseries CubeHash x1 &                                                                                   
      \raggedleft 152.70 & \raggedleft 151.93 & \raggedleft 2443  & \raggedleft 2430 &                          
      \raggedleft 745 & \raggedleft 672 & \raggedleft 3.28 & \raggedleft 3.62 \tabularnewline \hline            
      \bfseries CubeHash x1-PAR5 &                                                                              
      \raggedleft 151.26 & \raggedleft 151.56 & \raggedleft 12101 & \raggedleft 12125 &                         
      \raggedleft 3742 & \raggedleft 3490 & \raggedleft 3.23 & \raggedleft 3.47 \tabularnewline \hline          
      \bfseries CubeHash x1-PAR17 &                                                                             
      \raggedleft N/A & \raggedleft 150.49 & \raggedleft N/A & \raggedleft 40933 &                              
      \raggedleft N/A & \raggedleft 11360 & \raggedleft N/A & \raggedleft 1.91 \tabularnewline \hline           
      \bfseries CubeHash x1-PAR33 &                                                                             
      \raggedleft 150.65 & \raggedleft N/A & \raggedleft 79542 & \raggedleft N/A &                              
      \raggedleft 24570 & \raggedleft N/A & \raggedleft 3.24 & \raggedleft N/A \tabularnewline \hline           
      \bfseries CubeHash /2(h) &                                                                                
      \raggedleft 173.52 & \raggedleft 184.71 & \raggedleft 1388 & \raggedleft 1477 &                           
      \raggedleft 733 & \raggedleft 624 & \raggedleft 1.89 & \raggedleft 2.37 \tabularnewline \hline            


   \end{tabular}                                                                                                
\end{table*}                
share|improve this question
    
Welcome to TeX.SE. Please make an attempt to compose to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Your is not quite minimal. For example, can you reproduce the problem if you remove all the rows except one? Same for columns... –  Peter Grill Mar 7 '12 at 5:14
    
Why should you use \multicolumn{2}{>{\centering}m{3.0cm}|}{\bfseries Clock Frequency (MHz)} . The width is already defined above. I think you can simply put \multicolumn{2}{c|}{\bfseries Clock Frequency (MHz)}. What about adding \arraybackslash after \centering. If you provide a MWE as werner said it would be better. –  Harish Kumar Mar 7 '12 at 5:30
add comment

1 Answer

When using \multicolumn{1}, you don't need to respecify the column width via m{<len>}, since it requires a cumbersome interface when trying to centre the column entry. Rather just use \multicolumn{1}{c}{...}.

Here is an updated version of your code snippet:

enter image description here

\documentclass{article}
%\usepackage[landscape]{geometry}% http://ctan.org/pkg/geometry
\usepackage{array}% http://ctan.org/pkg/array
\newcommand{\stackcell}[2][c]{%
  \begin{tabular}{@{}#1@{}}
  #2
  \end{tabular}%
}
\begin{document}
\begin{table*}
   \centering
   \caption{Results on Xilinx Virtex 5 Devices}
   \label{tab:XilinxResults}
   \begin{tabular}{|>{\bfseries\arraybackslash}l|*{8}{>{\raggedleft\arraybackslash}m{13mm}|}}
      \cline{2-9}
      \multicolumn{1}{c|}{} &  % blank box
      \multicolumn{2}{c|}{\bfseries \stackcell{Clock Frequency\\(MHz)}} &
      \multicolumn{2}{c|}{\bfseries \stackcell{Throughput\\(Mbit/s)}} &
      \multicolumn{2}{c|}{\bfseries \stackcell{Area\\(CLB Slices)}} &
      \multicolumn{2}{c|}{\bfseries \stackcell{Throughput /\\Area}} \\ \hline
      \multicolumn{1}{|c|}{\bfseries Architecture} &
      \multicolumn{1}{c|}{\bfseries 512-bit} &
      \multicolumn{1}{c|}{\bfseries 256-bit} &
      \multicolumn{1}{c|}{\bfseries 512-bit} &
      \multicolumn{1}{c|}{\bfseries 256-bit} &
      \multicolumn{1}{c|}{\bfseries 512-bit} &
      \multicolumn{1}{c|}{\bfseries 256-bit} &
      \multicolumn{1}{c|}{\bfseries 512-bit} &
      \multicolumn{1}{c|}{\bfseries 256-bit}
      \tabularnewline\hline\hline

      BMW x1 & 4.89 & 8.14 & 5004  & 4168 & 12039 & 6164 & 0.42 & 0.68 \\ \hline
      BMW x1-PPL18 & 46.51 & 70.97 & 47628 & 36335 & 24564 & 11610 & 1.84 & 2.96 \\ \hline
      BMW /32(h) & 44.27 & 69.41 & 1416 & 1110 & 4001 & 2211 & 0.35 & 0.50 \\ \hline
      CubeHash x1 & 152.70 & 151.93 & 2443 & 2430 & 745 & 672 & 3.28 & 3.62 \\ \hline
      CubeHash x1-PAR5 & 151.26 & 151.56 & 12101 & 12125 & 3742 & 3490 & 3.23 & 3.47 \\ \hline
      CubeHash x1-PAR17 & N/A & 150.49 & N/A & 40933 & N/A & 11360 & N/A & 1.91 \\ \hline
      CubeHash x1-PAR33 & 150.65 & N/A & 79542 & N/A & 24570 & N/A & 3.24 & N/A \\ \hline
      CubeHash /2(h) & 173.52 & 184.71 & 1388 & 1477 & 733 & 624 & 1.89 & 2.37 \\ \hline
   \end{tabular}
\end{table*}
\end{document}

Hopefully this improves some of the formatting and readability of code. Some improvements include:

  • Using a repetition column specifier: *{<num>}{<col spec>} which repeats <col spec> a total of <num> times;
  • Inserting \raggedleft at the "column specification" level to avoid cluttering the tabular contents with \raggedleft;
  • Using \arraybackslash within >{<stuff>} in the column specifier, which restores the traditional use of \\ as \tabularnewline;
  • Added \stackcell[<col spec>]{<stuff>} which adds a stackable tabular within a cell (although you may not need/require this).

Finally, as a recommendation for professional-looking tables, consider using the booktabs package. The horizontal alignment/structure of a table lends itself to avoid using vertical rules, something promoted by/when using booktabs.

(geometry was loaded in landscape mode to make the table fit on the page when compiling the MWE.)

share|improve this answer
add comment

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.