TransWikia.com

Vertically centering text in latex tables

TeX - LaTeX Asked by Nicco on May 28, 2021

I am currently working on my master’s thesis and I am trying to input a table in my latex document. The following picture will describe what I am trying to achieve:

Centering text in a cell

I am trying to vertically center the text in cells 1 through 7 in the first line (Gruppe – max. GK-Größe) but do not seem to find a solution for this.

here is the example of the table I am using:

begin{table}[h]
centering
resizebox{linewidth}{!}{%
begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} 
hline
multirow{2}{*}{Gruppe~}                                      & multirow{2}{*}{Nr.~} & multirow{2}{*}{begin{tabular}[c]{@{}c@{}}UHPFRCSorte~ end{tabular}} & multirow{2}{*}{begin{tabular}[c]{@{}c@{}}Fasergehalt${[}Vol.-%]$~ end{tabular}} & multirow{2}{*}{begin{tabular}[c]{@{}c@{}}Faser $l/d$${[}mm]$ end{tabular}} & multirow{2}{*}{Konsistenz} & multirow{2}{*}{begin{tabular}[c]{@{}c@{}}max.GK-Größe${[}mm]$~ end{tabular}} & multicolumn{5}{c|}{Prüfumfang}                                                                                                                                                                                                                                                                                                                                                                               
cline{8-12}
                                                              &                       &                                                                          &                                                                                     &                                                                             &                             &                                                                                   & begin{tabular}[c]{@{}c@{}}Balken$150$x$50$x$550$${[}mm]$(hor. Herstellung)end{tabular} & begin{tabular}[c]{@{}c@{}}Balken$150$x$50$x$550$${[}mm]$(vert. Herstellung)end{tabular} & begin{tabular}[c]{@{}c@{}}Platten$450$x$450$x$50$${[}mm]$end{tabular} & begin{tabular}[c]{@{}c@{}}Würfel$100$x$100$x$100$${[}mm]$end{tabular} & begin{tabular}[c]{@{}c@{}}Zylinder$100$x$200$${[}mm]$end{tabular}   
hline
multirow{3}{*}{1}                                            & 1                     & FN                                                                       & 1                                                                                   & 12,5/0,192                                                                  & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
                                                              & 2                     & FM                                                                       & 2                                                                                   & 12,5/0,192                                                                  & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
                                                              & 3                     & FH                                                                       & 3                                                                                   & 12,5/0,192                                                                  & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                   
hline
multirow{3}{*}{2}                                            & 4                     & FN                                                                       & 1                                                                                   & 13/0,16                                                                     & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                  
                                                              & 5                     & FM                                                                       & 2                                                                                   & 13/0,16                                                                     & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                  
                                                              & 6                     & FH                                                                       & 3                                                                                   & 13/0,16                                                                     & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                   
hline
multirow{2}{*}{3}                                            & 7                     & FN                                                                       & 1                                                                                   & 20/0,3                                                                      & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
                                                              & 8                     & FH                                                                       & 3                                                                                   & 20/0,3                                                                      & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                   
hline
multirow{2}{*}{begin{tabular}[c]{@{}c@{}}4 end{tabular}} & 9                     & GM                                                                       & 1                                                                                   & 12,5/0,192                                                                  & SCC                         & 8                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
                                                              & 10                    & GN                                                                       & 1                                                                                   & 13/0,16                                                                     & SCC                         & 8                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                   
hline
multirow{2}{*}{5}                                            & 11                    & FN                                                                       & 1                                                                                   & 12,5/0,192                                                                  & F52                         & 1                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                  
                                                              & 12                    & FN                                                                       & 1                                                                                   & 12,5/0,192                                                                  & F52                         & 1                                                                                 & checkmark                                                                                             &                                                                                             &                                                                     & checkmark                                                                   & checkmark                                                                   
hline
multirow{2}{*}{6}                                            & 13                    & FN                                                                       & 1                                                                                   & 12,5/0,192                                                                  & SCC                         & 1                                                                                 &                                                                                               & checkmark                                                                                           &                                                                     & checkmark                                                                   & checkmark                                                                  
                                                              & 14                    & FH                                                                       & 3                                                                                   & 12,5/0,192                                                                  & SCC                         & 1                                                                                 &                                                                                               & checkmark                                                                                           &                                                                     & checkmark                                                                   & checkmark                                                                   
hline
multirow{2}{*}{begin{tabular}[c]{@{}c@{}}7 end{tabular}} & 15                    & G-                                                                       & 0                                                                                   &                                                                             & SCC                         & 8                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
                                                              & 16                    & F-                                                                       & 0                                                                                   &                                                                             & SCC                         & 1                                                                                 & checkmark                                                                                             &                                                                                             & checkmark                                                                   & checkmark                                                                   & checkmark                                                                  
hline
end{tabular}}
caption{Versuchsprogramm}
label{tab:Versuchsprogramm}
end{table}

Please note, that I am using the usepackage[ngerman]{babel} for German language.

Can anyone help me with this issue?

Thank you very much!
Nicco

2 Answers

You can do that with {NiceTabular} of nicematrix.

With the command multirow of multirow, you have to provide the number of physical lines. With the command Block (provided by nicematrix) you provide the number of logaical rows of the tabular and the content is mathematically centered.

You can use Block to merge cells both vertically and horizontally and then use the key hvlines to draw all the rules, excepted in the blocks.

documentclass{article}
usepackage{graphicx}
usepackage{dingbat}
usepackage{siunitx}
usepackage{makecell}
usepackage{geometry}
usepackage{pdflscape}
usepackage{nicematrix}
NiceMatrixOptions{cell-space-top-limit=2pt,cell-space-bottom-limit=2pt}

begin{document}
begin{landscape}
begin{table}
centering
caption{Versuchsprogramm}
label{tab:Versuchsprogramm}
begin{NiceTabular}{*{12}{c}}[hvlines]
Block{2-1}{Gruppe} 
  & Block{2-1}{Nr.} 
    & Block{2-1}{UHPFRCSorte} 
      & Block{2-1}{Fasergehalt{} [Vol.-%]}
        & Block{2-1}{Faser $l/d${} [si{mm}]}
          & Block{2-1}{Konsistenz}
            & Block{2-1}{max. GK-Größe{} [si{mm}]}
  & Block{1-5}{Prüfumfang}   
  &  &  &  &  &  &   
            & Block{}{Balken (hor.)} 
              & Block{}{Balken (vert.)} 
                & Platten
                  & Würfel
                    & Zylinder   
Block{3-1}{1} & 1  & FN & 1 & 12,5/0,192 & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
                   & 2  & FM & 2 & 12,5/0,192 & SCC &   & checkmark &            & checkmark & checkmark & checkmark  
                   & 3  & FH & 3 & 12,5/0,192 & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
Block{3-1}{2} & 4  & FN & 1 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark  
                   & 5  & FM & 2 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark  
                   & 6  & FH & 3 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark   
Block{2-1}{3} & 7  & FN & 1 & 20/0,3     & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
                   & 8  & FH & 3 & 20/0,3     & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
Block{2-1}{4} & 9  & GM & 1 & 12,5/0,192 & SCC & 8 & checkmark &            & checkmark & checkmark & checkmark  
                   & 10 & GN & 1 & 13/0,16    & SCC & 8 & checkmark &            &            & checkmark & checkmark   
Block{2-1}{5} & 11 & FN & 1 & 12,5/0,192 & F52 & 1 & checkmark &            &            & checkmark & checkmark  
                   & 12 & FN & 1 & 12,5/0,192 & F52 & 1 & checkmark &            &            & checkmark & checkmark   
Block{2-1}{6} & 13 & FN & 1 & 12,5/0,192 & SCC & 1 &            & checkmark &            & checkmark & checkmark  
                   & 14 & FH & 3 & 12,5/0,192 & SCC & 1 &            & checkmark &            & checkmark & checkmark   
Block{2-1}{7} & 15 & G- & 0 &            & SCC & 8 & checkmark &            & checkmark       & checkmark       & checkmark      
                   & 16 & F- & 0 &            & SCC & 1 & checkmark &            & checkmark       & checkmark       & checkmark      
end{NiceTabular}
end{table}
end{landscape}

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Correct answer by F. Pantigny on May 28, 2021

Here is my suggestion. In addition to adapting the second argument of multirow according to the actual number of lins of text, rather than to the number of table rows, I also made some further adjustments. First of all, I used siunitx for the units, removed resizebox and rotated teh table to a landscape orientation. In order to make sure the table first into the textwidth, I shortened the column headers and placed the removed information below the table. I also added the cellspace package to add a small amount of vertical shite space around the cells. As an aternatiev, I also included a second, different table layout based on booktabs:

enter image description here

enter image description here

documentclass{article}
usepackage{multirow}
usepackage{graphicx}
usepackage{dingbat}
usepackage{siunitx}
usepackage{makecell}
usepackage{geometry}
usepackage{pdflscape}
usepackage[column=0]{cellspace}
setlength{cellspacetoplimit}{2pt}
setlength{cellspacebottomlimit}{cellspacetoplimit}
usepackage{booktabs}

begin{document}
begin{landscape}
begin{table}
centering
caption{Versuchsprogramm}
label{tab:Versuchsprogramm}
begin{tabular}{|*{12}{0c|}} 
hline
multirow{3.5}{*}{thead{Gruppe}} 
  & multirow{3.5}{*}{thead{Nr.}} 
    & multirow{3.5}{*}{thead{UHPFRCSorte}} 
      & multirow{3.5}{*}{thead{Fasergehalt{} [Vol.-%]}} 
        & multirow{3.5}{*}{thead{Faser $l/d${} [si{mm}]}} 
          & multirow{3.5}{*}{thead{Konsistenz}} 
            & multirow{3.5}{*}{thead{max. GK-Größe{} [si{mm}]}} 
  & multicolumn{5}{c|}{thead{Prüfumfang}}   
cline{8-12}
  &  &  &  &  &  &   
            & thead{Balken (hor.)} 
              & thead{Balken (vert.)} 
                & thead{Platten} 
                  & thead{Würfel} 
                    & thead{Zylinder}   
hline
multirow{3}{*}{1} & 1  & FN & 1 & 12,5/0,192 & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
                   & 2  & FM & 2 & 12,5/0,192 & SCC &   & checkmark &            & checkmark & checkmark & checkmark  
                   & 3  & FH & 3 & 12,5/0,192 & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
hline
multirow{3}{*}{2} & 4  & FN & 1 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark  
                   & 5  & FM & 2 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark  
                   & 6  & FH & 3 & 13/0,16    & SCC & 1 & checkmark &            &            & checkmark & checkmark   
hline
multirow{2}{*}{3} & 7  & FN & 1 & 20/0,3     & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
                   & 8  & FH & 3 & 20/0,3     & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
hline
multirow{2}{*}{4} & 9  & GM & 1 & 12,5/0,192 & SCC & 8 & checkmark &            & checkmark & checkmark & checkmark  
                   & 10 & GN & 1 & 13/0,16    & SCC & 8 & checkmark &            &            & checkmark & checkmark   
hline
multirow{2}{*}{5} & 11 & FN & 1 & 12,5/0,192 & F52 & 1 & checkmark &            &            & checkmark & checkmark  
                   & 12 & FN & 1 & 12,5/0,192 & F52 & 1 & checkmark &            &            & checkmark & checkmark   
hline
multirow{2}{*}{6} & 13 & FN & 1 & 12,5/0,192 & SCC & 1 &            & checkmark &            & checkmark & checkmark  
                   & 14 & FH & 3 & 12,5/0,192 & SCC & 1 &            & checkmark &            & checkmark & checkmark   
hline
multirow{2}{*}{7} & 15 & G- & 0 &            & SCC & 8 & checkmark &            & checkmark       & checkmark       & checkmark      
                   & 16 & F- & 0 &            & SCC & 1 & checkmark &            & checkmark       & checkmark       & checkmark      
hline
multicolumn{12}{l}{}
multicolumn{12}{@{}l}{small Balken (hor.) = SI{150x50x550}{mm}, horizontale Herstellung}
multicolumn{12}{@{}l}{small Balken (vert.) = SI{150x50x550}{mm}, vertikale Herstellung}
multicolumn{12}{@{}l}{small Platten = SI{450x450x50}{mm}}
multicolumn{12}{@{}l}{small Würfel = SI{100x100x100}{mm}}
multicolumn{12}{@{}l}{small Zylinder = SI{100x200}{mm}}
end{tabular}
end{table}
end{landscape}

begin{landscape}
begin{table}
centering
caption{Versuchsprogramm}
label{tab:Versuchsprogramm}
begin{tabular}{*{4}{c}l@{~/~}l *{7}{c}} 
toprule
thead{Gruppe}
  & thead{Nr.}
    & multirow[t]{3}{*}{thead[t]{UHPFRCSorte}}
      & multirow[t]{3}{*}{thead[t]{Fasergehalt{} [Vol.-%]}} 
        & multicolumn{2}{c}{multirow[t]{3}{*}{thead[t]{Faser $l/d${} [si{mm}]}}} 
          & multirow[t]{3}{*}{thead[t]{Konsistenz}} 
            & multirow[t]{3}{*}{thead[t]{max. GK-Größe{} [si{mm}]}} 
  & multicolumn{5}{c}{thead{Prüfumfang}}   
cmidrule{9-13}
  &  &  & multicolumn{2}{c}{}   &  &  &   
            & thead{Balken (hor.)} 
              & thead{Balken (vert.)} 
                & thead{Platten} 
                  & thead{Würfel} 
                    & thead{Zylinder}   
midrule
1 & 1  & FN & 1 & 12,5 & 0,192         & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
  & 2  & FM & 2 & 12,5 & 0,192         & SCC &   & checkmark &            & checkmark & checkmark & checkmark  
  & 3  & FH & 3 & 12,5 & 0,192         & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
addlinespace
2 & 4  & FN & 1 & 13   & 0,16          & SCC & 1 & checkmark &            &            & checkmark & checkmark  
  & 5  & FM & 2 & 13   & 0,16          & SCC & 1 & checkmark &            &            & checkmark & checkmark  
  & 6  & FH & 3 & 13   & 0,16          & SCC & 1 & checkmark &            &            & checkmark & checkmark   
addlinespace
3 & 7  & FN & 1 & 20   & 0,3           & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark  
  & 8  & FH & 3 & 20   & 0,3           & SCC & 1 & checkmark &            & checkmark & checkmark & checkmark   
addlinespace
4 & 9  & GM & 1 & 12,5 & 0,192         & SCC & 8 & checkmark &            & checkmark & checkmark & checkmark  
  & 10 & GN & 1 & 13   & 0,16          & SCC & 8 & checkmark &            &            & checkmark & checkmark   
addlinespace
5 & 11 & FN & 1 & 12,5 & 0,192         & F52 & 1 & checkmark &            &            & checkmark & checkmark  
  & 12 & FN & 1 & 12,5 & 0,192         & F52 & 1 & checkmark &            &            & checkmark & checkmark   
addlinespace
6 & 13 & FN & 1 & 12,5 & 0,192         & SCC & 1 &            & checkmark &            & checkmark & checkmark  
  & 14 & FH & 3 & 12,5 & 0,192         & SCC & 1 &            & checkmark &            & checkmark & checkmark   
addlinespace
8 & 15 & G- & 0 & multicolumn{2}{c}{} & SCC & 8 & checkmark &            & checkmark       & checkmark       & checkmark      
  & 16 & F- & 0 & multicolumn{2}{c}{} & SCC & 1 & checkmark &            & checkmark       & checkmark       & checkmark      
bottomrule
addlinespace
multicolumn{12}{@{}l}{small Balken (hor.) = SI{150x50x550}{mm}, horizontale Herstellung}
multicolumn{12}{@{}l}{small Balken (vert.) = SI{150x50x550}{mm}, vertikale Herstellung}
multicolumn{12}{@{}l}{small Platten = SI{450x450x50}{mm}}
multicolumn{12}{@{}l}{small Würfel = SI{100x100x100}{mm}}
multicolumn{12}{@{}l}{small Zylinder = SI{100x200}{mm}}
end{tabular}
end{table}
end{landscape}
end{document}

Answered by leandriis on May 28, 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