TransWikia.com

Border for one column in Latex

TeX - LaTeX Asked by ali-sezar on August 13, 2021

I am new to latex and I have trouble to find out what is going on in table environment.
I have a table and want to separate every 3 column with each other to look like this:
enter image description here

But my tex is like below:

documentclass{article}
usepackage{placeins}
usepackage{booktabs ,float}
begin{document}
begin{table}
begin{tabular}{ccclllllllll}
hline
multicolumn{1}{|c|}{textbf{i}} & multicolumn{1}{c|}{textbf{Z_i}} & multicolumn{1}{c|}{textbf{U_i}} & multicolumn{1}{c|}{textbf{i}} & multicolumn{1}{c|}{textbf{Z_i}} & multicolumn{1}{c|}{textbf{U_i}} & multicolumn{1}{c|}{textbf{i}} & multicolumn{1}{c|}{textbf{Z_i}} & multicolumn{1}{c|}{textbf{U_i}} & multicolumn{1}{c|}{textbf{i}} & multicolumn{1}{c|}{textbf{Z_i}} & multicolumn{1}{c|}{textbf{U_i}}  hline
0                                & 7                                  & -                                  & 5                               & 10                                 & 0.652                              & 10                              & 9                                  & 0.563                              & 15                              & 4                                  & 0.250                              
1                                & 6                                  & 0.375                              & 6                               & 5                                  & 0.313                              & 11                              & 0                                  & 0.000                              & 16                              & 7                                  & 0.438                              
2                                & 1                                  & 0.063                              & 7                               & 12                                 & 0.750                              & 12                              & 3                                  & 0.188                              & 17                              & 6                                  & 0.375                              
3                                & 8                                  & 0.500                              & 8                               & 15                                 & 0.938                              & 13                              & 2                                  & 0.125                              & 18                              & 1                                  & 0.063                              
4                                & 11                                 & 0.688                              & 9                               & 14                                 & 0.875                              & 14                              & 13                                 & 0.813                              & 19                              & 8                                  & 0.500                             
end{tabular}
end{table} 
end{document}

Thanks in advance for the answers.

2 Answers

Removing all the occurences of multicolumn{1}{|c|} in combination with using begin{tabular}{ccc|ccc|ccc|ccc} should result in an output closer to the expected one. Personally, I recommend to not use vertical lines in a table. Instead you could use horizontal white space in combination with interrupted horizontal lines from the booktabs package in order to create a visual separation between teh 4 blocks in your table. For an improved alignment of numbers in your table, you may also want to consider using S type columns from siunitx.

enter image description here

documentclass{article}
usepackage{placeins}
usepackage{booktabs ,float}
begin{document}
begin{tabular}{ccc|ccc|ccc|ccc}
hline
$i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$   hline
0                                & 7                                  & -                                  & 5                               & 10                                 & 0.652                              & 10                              & 9                                  & 0.563                              & 15                              & 4                                  & 0.250                              
1                                & 6                                  & 0.375                              & 6                               & 5                                  & 0.313                              & 11                              & 0                                  & 0.000                              & 16                              & 7                                  & 0.438                              
2                                & 1                                  & 0.063                              & 7                               & 12                                 & 0.750                              & 12                              & 3                                  & 0.188                              & 17                              & 6                                  & 0.375                              
3                                & 8                                  & 0.500                              & 8                               & 15                                 & 0.938                              & 13                              & 2                                  & 0.125                              & 18                              & 1                                  & 0.063                              
4                                & 11                                 & 0.688                              & 9                               & 14                                 & 0.875                              & 14                              & 13                                 & 0.813                              & 19                              & 8                                  & 0.500                             
end{tabular}
bigskip

begin{tabular}{ccc@{qquad}ccc@{qquad}ccc@{qquad}ccc}
toprule
$i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$ 
& $i$ & $Z_i$  & $U_i$   
cmidrule(r{2em}){1-3} cmidrule(r{2em}){4-6} cmidrule(r{2em}){7-9} cmidrule{10-12}
0 & 7   & --       & 5  & 10  & 0.652   & 10   & 9   & 0.563  & 15  & 4   & 0.250     
1 & 6   & 0.375    & 6  & 5   & 0.313   & 11   & 0   & 0.000  & 16  & 7   & 0.438     
2 & 1   & 0.063    & 7  & 12  & 0.750   & 12   & 3   & 0.188  & 17  & 6   & 0.375     
3 & 8   & 0.500    & 8  & 15  & 0.938   & 13   & 2   & 0.125  & 18  & 1   & 0.063     
4 & 11  & 0.688    & 9  & 14  & 0.875   & 14   & 13  & 0.813  & 19  & 8   & 0.500       
bottomrule
end{tabular}
end{document}

Correct answer by leandriis on August 13, 2021

I suggest you get rid of the multicolumn{1}{c}{...} wrappers, employ an array environment instead of a tabular environment, and replace all instances of textbf with bm. I would also align the numbers in the "Z" columns on their (implicit) decimal markers.

enter image description here

documentclass{article}
usepackage{siunitx,bm}
usepackage{newtxtext,newtxmath} % optional: Times Roman text and math fonts
begin{document}
begin{table}
[
begin{array}{@{} *{3}{c S[table-format=2.0] c|} ccc @{}}
hline
bm{i} & {bm{Z}_i} & bm{U}_{!i} & bm{i} & {bm{Z}_i} & bm{U}_{!i} & 
bm{i} & {bm{Z}_i} & bm{U}_{!i} & bm{i} & {bm{Z}_i} & bm{U}_{!i}  
hline
0  & 7 & textup{--} & 5 & 10 & 0.652& 10& 9  & 0.563& 15& 4 & 0.250
1  & 6   & 0.375& 6 & 5   & 0.313& 11& 0   & 0.000& 16& 7   & 0.438
2  & 1   & 0.063& 7 & 12  & 0.750& 12& 3   & 0.188& 17& 6   & 0.375
3  & 8   & 0.500& 8 & 15  & 0.938& 13& 2   & 0.125& 18& 1   & 0.063
4  & 11  & 0.688& 9 & 14  & 0.875& 14& 13  & 0.813& 19& 8   & 0.500
end{array}
]
end{table} 
end{document}

Answered by Mico on August 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP