1

I got table, which, for the sake of brevity I dumbed down to the following,

\begin{tabular}{ |l|l|c c c|l|l|l| }
    \hline
    Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{ |c| }{Solution to $C_k$} & Current & Pursue & Stored\\
    & & $x_1$ & $x_2$ & $z$ & & & \\ \hline
\end{tabular}

which produces the following output

enter image description here

Now, I got two questions, both related to the multi-column. First is it possible to generate a partial \hline that only affect the third column (Separating the "Solution to C_k" label and the three variables)?

Secondly, it looks like $x_1$, $x_2$ and $z$ are not being centred. How can this be recitifed?

  • (i) \cline{3-5}, (ii) \multicolumn{3}{c}{Solution to $C_k$} is wider than sum of width of spanned columns, consequently column with $z$ is extended. you should redefine c columns, for example to >{\centering\arraybackslash}p{....} – Zarko Feb 23 '18 at 16:28
  • (i) thanks! :D (ii) is there any way I can easily size each of the spanned columns as a third of the column spanning them? – JustDanyul Feb 23 '18 at 16:32
  • i show in comment haw ... i will write an answer ... – Zarko Feb 23 '18 at 16:34
2

enter image description here

spotted asymmetry of c column width arise from fact that \multicolumn{3}{c}{Solution to $C_k$} is wider than sum of widths of spanned columns. consequently column contain $z$ is extended to fit width of multi column cell.

to have all c columns equal width you had to prescribe their width, for example with help of column type p{<width>}:

\documentclass{article}
\usepackage{array}% needed for column redefinition
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{tabular}{ |l|l|*{3}{C{2em}}|l|l|l| }
    \hline
Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{c|}{Solution to $C_k$}
    & Current & Pursue & Stored     \\
    \cline{3-5}
    & & $x_1$ & $x_2$ & $z$ & & & \\
    \hline
\end{tabular}
\end{document}

however, i would rather design table on the following way:

enter image description here

\documentclass{article}
\usepackage{array, booktabs}% needed for column redefinition and nicer looks
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{tabular}{ ll *{3}{C{2em}} lll}
    \toprule
    &   & \multicolumn{3}{c}{Solution to $C_k$} &   &   &   \\
    \cmidrule(lr){3-5}
Problem $I_k$ & Solved $C_k$ & $x_1$ & $x_2$ & $z$ & Current & Pursue & Stored     \\
     \midrule
\end{tabular}
\end{document}
  • you are welcome. now i added some of-topic thoughts :-) – Zarko Feb 23 '18 at 16:52
1

Here is a variant using the tabularx package to make the table automatically spread to textwidth without manually specifying the column's widths.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{ |l|l|*3{>{\centering\arraybackslash}X}|l|l|l| }
    \hline
    Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{ c| }{Solution to $C_k$} & Current & Pursue & Stored\\\cline{3-5} 
    & & $x_1$ & $x_2$ & $z$ & & & \\ \hline
\end{tabularx}
\end{document} 

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.