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 want to make a table like this one: enter image description here

I've using: enter image description here

and got the table enter image description here

Please help me to adjust the width of columns Y1, Y2, and Y3 equally. Many thanks!

share|improve this question
4  
Please post your code as code rather than an image. That way people can copy and paste it to work with it easily. You can format it as code by highlighting it and using the {} button or by indenting it all 4 spaces. Maybe the tabularx package is helpful here? That provides an X column which might do what you want. But I'm not sure and I can't modify your imaged code to test... –  cfr Jan 5 at 4:02
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  karlkoeller Jan 5 at 9:22

3 Answers 3

When a multicolumn entry is wider than the columns it spans, the extra space is put into the last spanned column.

A way to avoid that is to define a new length that matches the length of the contents of the multicolumn cell

\newlength\mylength
\settowidth\mylength{Measured surface roughness $R_a$ ($\mu$m)}

and then use 3 columns which width is 1/3 of this length (>{\centering\arraybackslash}p{.333\mylength})

Complete code:

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{array}

\begin{document}

\newlength\mylength
\settowidth\mylength{Measured surface roughness $R_a$ ($\mu$m)}

\begin{tabular}{l*{5}{c}*{3}{>{\centering\arraybackslash}p{.333\mylength}}*{2}{c}}
\hline\noalign{\smallskip}
{} & \multicolumn{5}{c}{Factor} & \multicolumn{3}{c}{Measured surface roughness $R_a$ ($\mu$m)} &
\multicolumn{2}{c}{Responses} \\
\cline{2-6}\cline{10-11}\noalign{\smallskip}
Trial No. & A & B & C & D & E & Y1 & Y2 & Y3 & Mean ($\mu$m) & $S/N$ ratios (dB) \\
\hline\noalign{\smallskip}
1&1&1&1&1&1&0.30&0.33&0.37&0.333&9.5104\\
2&1&1&2&2&2&0.26&0.28&0.26&0.267&11.4752\\
3&1&1&3&3&3&0.35&0.33&0.32&0.333&9.5363\\
\hline\noalign{\smallskip}
\end{tabular}

\end{document} 

Output

enter image description here

share|improve this answer

An alternative is the use of tabularx where a macro for Y column is defined as \newcolumntype{C} having the X column property. So that X columns can adjust to fit the \linewidth set for the table.

enter image description here

Code

\documentclass[]{article}
\usepackage[margin=1in]{geometry}
\usepackage{array}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}

\begin{document}
\noindent  % use this or wrap it in a table environment -- reminded by Mico, thanks.  
\begin{tabularx}{\linewidth}{l*5{c}*3{C{1}}*2{c}}
\hline\noalign{\smallskip}
{} & \multicolumn{5}{c}{Factor} & \multicolumn{3}{c}{Measured surface roughness $R_a$ ($\mu$m)} &
\multicolumn{2}{c}{Responses} \\
\cline{2-6}\cline{10-11}\noalign{\smallskip}
Trial No. & A & B & C & D & E & Y1 & Y2 & Y3 & Mean ($\mu$m) & $S/N$ ratios (dB) \\
\hline\noalign{\smallskip}
1&1&1&1&1&1&0.30&0.33&0.37&0.333&9.5104\\
2&1&1&2&2&2&0.26&0.28&0.26&0.267&11.4752\\
3&1&1&3&3&3&0.35&0.33&0.32&0.333&9.5363\\
\hline\noalign{\smallskip}
\end{tabularx}
\end{document} 
share|improve this answer
    
You should probably insert \noindent before the start of the tabularx environment -- or encase it in a table environment. –  Mico Jan 5 at 10:41
    
Thanks Mico. Yes. –  Jesse Jan 5 at 10:48
1  
You've left the dirty work to me... :-) –  karlkoeller Jan 5 at 10:52
    
@karlkoeller -- Nay, I admire you work (which is a must to read) in this site. –  Jesse Jan 5 at 10:55
    
Thanks, you're too kind. –  karlkoeller Jan 5 at 22:18

Building on the answer by @Jesse and, in particular, using the machinery of the tabularx package, I would suggest you also do the following:

  • Rather than use \noalign{\smallskip} directives to get more vertical space around the table's horizontal lines, I would load the booktabs package and use its macros \toprule, \cmidrule, \midrule, and \bottomrule. These macros will automatically insert the proper amounts of vertical space. And, unlike the cline command, \cmidrule allows trimming on the left and right, allowing you to have adjoining lines that don't touch.

  • For the numerical entries in the final two columns, it may make sense to align the numbers on their decimal points. I suggest you use the S column type (provided by the siunitx package) for this purpose.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularx,booktabs,siunitx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\addtocounter{table}{3} % just for this example
\begin{table}
\caption{Small ball-furnished surface roughness of OFC}
\begin{tabularx}{\textwidth}{l *5{c} *3{C} 
  *2{S[table-format=2.4]}}
\toprule
Trial No.\ & \multicolumn{5}{c}{Factor} & \multicolumn{3}{c}{Measured surface roughness $R_a$ ($\mu$m)} &
\multicolumn{2}{c}{Responses} \\
\cmidrule(lr){2-6}\cmidrule(lr){7-9} \cmidrule(l){10-11}
 & A & B & C & D & E & Y1 & Y2 & Y3 & 
{Mean ($\mu$m)} & {$S/N$ ratios (dB)} \\
\midrule
1&1&1&1&1&1&0.30&0.33&0.37&0.333&9.5104\\
2&1&1&2&2&2&0.26&0.28&0.26&0.267&11.4752\\
3&1&1&3&3&3&0.35&0.33&0.32&0.333&9.5363\\
\bottomrule
\end{tabularx}
\end{table}
\end{document} 
share|improve this answer

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.