# Multi-columns. Distribution and horizontal lines

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

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

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:

\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

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}