TransWikia.com

Make a table like this but centering each cell vertically

TeX - LaTeX Asked on August 28, 2021

I would like a table like this but with the proper vertical spacing in each cell. I can’t find the way to do it.
e


begin{table}[hb]
    centering
    resizebox{14.5cm}{!}{%
        begin{tabular}{|c|c|c|l|}
            hline
            Tipus & Funció & multicolumn{2}{c|}{Mecanismes}  hline
            multirow{7}{*}{begin{tabular}[c]{@{}c@{}}Mecanismes de transmissió del movimentend{tabular}} & multirow{7}{*}{begin{tabular}[c]{@{}c@{}}Transmeten el moviment, la força i la potènciaend{tabular}} & multirow{3}{*}{begin{tabular}[c]{@{}c@{}}Transmissió linealend{tabular}} & Politja  cline{4-4} 
            &  &  & Polispast  cline{4-4} 
            &  &  & Palanca  cline{3-4} 
            &  & multirow{4}{*}{begin{tabular}[c]{@{}c@{}}Transmissió circularend{tabular}} & Rodes de fricció  cline{4-4} 
            &  &  & begin{tabular}[c]{@{}l@{}}Sistemes de politja i corretjaend{tabular}  cline{4-4} 
            &  &  & Engranatges  cline{4-4} 
            &  &  & Cadenes  hline
            multirow{7}{*}{begin{tabular}[c]{@{}c@{}}Mecanismes de transformació  del movimentend{tabular}} & multirow{7}{*}{begin{tabular}[c]{@{}c@{}}Transformen el moviment circular en rectilini o a la inversaend{tabular}} & multirow{4}{*}{begin{tabular}[c]{@{}c@{}}Transforma el moviment circularen rectilini o viceversaend{tabular}} & Manivela-torn  cline{4-4} 
            &  &  & Pinyó cremallera  cline{4-4} 
            &  &  & Cargol  cline{4-4} 
            &  &  & Vis sense fi  cline{3-4} 
            &  & multirow{3}{*}{begin{tabular}[c]{@{}c@{}}Transforma el moviment circular en rectilini alternat o viceversaend{tabular}} & Biela-manovella  cline{4-4} 
            &  &  & begin{tabular}[c]{@{}l@{}}Lleves i excèntriquesend{tabular}  cline{4-4} 
            &  &  & Cigonyal  hline
            multirow{5}{*}{begin{tabular}[c]{@{}c@{}}Mecanismes auxiliarsend{tabular}} & multicolumn{2}{l|}{multirow{5}{*}{begin{tabular}[c]{@{}l@{}}Modifiquen o controlen alguns paràmetres del moviment: Gir en un sol sentit (trinquet), reduir la velocitat de gir (frens), emmagatzemar energia (molles), acoblament d'eixos i arbre de transmissió (embragatge i acoblaments)end{tabular}}} & Trinquets  cline{4-4} 
            & multicolumn{2}{l|}{} & Frens  cline{4-4} 
            & multicolumn{2}{l|}{} & Molles  cline{4-4} 
            & multicolumn{2}{l|}{} & Embragatges  cline{4-4} 
            & multicolumn{2}{l|}{} & Acoblaments  hline
        end{tabular}%
    }
    caption{Mecanismes}
    label{tab:mecanismes}
end{table}

documentclass[a4paper,12pt]{report}
usepackage{geometry}
usepackage{amsmath,amssymb}
usepackage{siunitx}
usepackage{cancel}
usepackage{fancyhdr}
usepackage{lipsum}
usepackage{url}
usepackage{graphicx}
usepackage[nottoc,notlot,notlof]{tocbibind}
usepackage{titlesec}
usepackage[greek,catalan]{babel}
usepackage[titletoc]{appendix}
usepackage{relsize}
usepackage[numbers,square,super,sort&compress]{natbib}
usepackage{tabularx}
usepackage[hang,flushmargin]{footmisc}
usepackage{multirow}
usepackage[hidelinks]{hyperref}

setlength{parindent}{0pt}

textheight=630pt   
setlength{footskip}{2.1cm}

One Answer

Like this?

enter image description here

  • Please always provide small complete document (MWE: Minimal Working Example) which reproduce your problem. In your case we haven't any information about your document and its page layout (which has strong influence on table design)
  • In my MWE below are used:
    • the tabularx package, which enable prescription of table width and automatic determination of the columns width.
    • In use of multirow cells is exploited option = which overtake width of the column where it is-Cnsequently tables inside in those cells are not needed anymore.
    • Complete MWe is:
documentclass{article}
usepackage[margin=25mm]{geometry}
usepackage{multirow, 
            tabularx}   % new
newcolumntype{C}{>{centeringarraybackslash}X}
usepackage{xparse}     % new
NewExpandableDocumentCommandmcc{O{c|}m}
    {multicolumn{2}{#1}{#2}}

begin{document}
    begin{table}[hb]
    centering
    small
    renewcommandarraystretch{1.2}
    renewcommandtabularxcolumn[1]{m{#1}}
begin{tabularx}{linewidth}{|C|C|C|l|}
    hline
    Tipus & Funció & mcc{Mecanismes}  hline
multirow{7}{=}{centering
                Mecanismes de transmissió del moviment} 
    & multirow{7}{=}{centering
                      Transmeten el moviment, la força i la potència} 
        & multirow{3}{=}{Transmissió lineal} 
            & Politja                cline{4-4}
    &   &   & Polispast              cline{4-4}
    &   &   & Palanca                cline{3-4}
    &  & multirow{4}{=}{centering
                          Transmissió circular} 
            & Rodes de fricció       cline{4-4}
    &  &  & Sistemes de politja i corretja   cline{4-4}
    &  &  & Engranatges              cline{4-4}
    &  &  & Cadenes                  hline
multirow{7}{=}{centering
                Mecanismes de transformació del moviment} 
    & multirow{7}{=}{centering
                      Transformen el moviment circular en rectilini o a la inversa} 
        & multirow{4}{=}{centering
                          Transforma el moviment circularen rectilini o viceversa} 
            & Manivela-torn          cline{4-4}
    &   &   & Pinyó cremallera       cline{4-4}
    &   &   & Cargol                 cline{4-4}
    &   &   & Vis sense fi           cline{3-4}
    &   & multirow{3}{=}{centering
                          Transforma el moviment circular en rectilini alternat o viceversa} 
            & Biela-manovella        cline{4-4}
    &  &  & Lleves i excèntriques    cline{4-4}
    &  &  & Cigonyal                 hline
multirow{5}{=}{Mecanismes auxiliars} 
        & multicolumn{2}{>{hsize=dimexpr2hsize+2tabcolsep+arrayrulewidthrelax}X|}
                      {multirow{5}{=}{Modifiquen o controlen alguns paràmetres del moviment:
                                       Gir en un sol sentit (trinquet), reduir la velocitat de 
                                       gir (frens), emmagatzemar energia (molles), acoblament 
                                       d'eixos i arbre de transmissió (embragatge i acoblaments)}} 
            & Trinquets                      cline{4-4}
    & mcc{} & Frens                 cline{4-4}
    & mcc{} & Molles                cline{4-4}
    & mcc{} & Embragatges           cline{4-4}
    & mcc{} & Acoblaments           hline
end{tabularx}%
caption{Mecanismes}
    label{tab:mecanismes}
    end{table}
end{document}

Addendum: Page margins of OP document are larger as it was anticipated in the first version of answer. Therefore in cells are less space for text and consequently they in some multirow cells spil out on bottom of cells.

As workaround in the following MWE, the following measures are considered:

  • reduced is baseline skip with
smalllinespread{.84}selectfontrelax
  • reduced are size of tabcolsep
  • first column in table is narrowed and next two are widened
  • increased is vertical space above and below cells content by use of the macro makegapedcells
  • because makegapedcells and m column types are incompatible, in preamble is added fix provided by Ulrike Fisher.
  • new MWE is then:
documentclass[a4paper,12pt]{report}
usepackage{geometry}

usepackage{makecell,      % new
            multirow,tabularx}
newcolumntype{C}{>{centeringarraybackslash}X}
%%  patch of Ulrike Fisher (on my request)  --------------------%
%   (http://tex.stackexchange.com/questions/319768/             %
%               are-m-column-type-and-makecell-incompatible)    %
%%  for makecell macro makegapedcells                          %
%%--------------------------------------------------------------%
makeatletter
renewcommandmcell@classz{@classx
@tempcnta count@
prepnext@tok
@addtopreamble{%mcell@mstyle
      ifcase@chnum
         hfil
         mcell@agape{d@llarbegininsert@columnd@llarend}hfil or
         hskip1sp
         mcell@agape{d@llarbegininsert@columnd@llarend}hfil or
         hfilhskip1sp
         mcell@agape{d@llarbegin insert@columnd@llarend}or
         mcell@agape{$vcenter
         @startpbox{@nextchar}insert@column@endpbox$}or
         mcell@agape{vtop
         @startpbox{@nextchar}insert@column@endpbox}or
         mcell@agape{vbox
        @startpbox{@nextchar}insert@column@endpbox}%
      fi
      globalletmcell@leftrelaxgloballetmcell@rightrelax
    }prepnext@tok}
makeatother
usepackage{xparse}     % new
NewExpandableDocumentCommandmcc{O{c|}m}
    {multicolumn{2}{#1}{#2}}

begin{document}
    begin{table}[hb]
    centering
    smalllinespread{.84}selectfontrelax  % <---
    setlengthtabcolsep{3pt}                % <---
    setcellgapes{3pt}
    makegapedcells
    renewcommandtabularxcolumn[1]{m{#1}}
begin{tabularx}{linewidth}{|>{hsize=0.8hsize}C|
                         *{2}{>{hsize=1.1hsize}C|}l|}  % <---
    hline
    Tipus & Funció & mcc{Mecanismes}  hline
multirow{10}{=}{centering
                Mecanismes de transmissió del moviment}
    & multirow{10}{=}{centering
                      Transmeten el moviment, la força i la potència}
        & multirow{5}{=}{Transmissió lineal}
            & Politja                cline{4-4}
    &   &   & Polispast              cline{4-4}
    &   &   & Palanca                cline{3-4}
    &  & multirow{5}{=}{centering
                          Transmissió circular}
            & Rodes de fricció       cline{4-4}
    &  &  & Sistemes de politja i corretja   cline{4-4}
    &  &  & Engranatges              cline{4-4}
    &  &  & Cadenes                  hline
multirow{10}{=}{centering
                Mecanismes de transformació del moviment}
    & multirow{10}{=}{centering
                      Transformen el moviment circular en rectilini o a la inversa}
        & multirow{6}{=}{centering
                          Transforma el moviment circularen rectilini o viceversa}
            & Manivela-torn          cline{4-4}
    &   &   & Pinyó cremallera       cline{4-4}
    &   &   & Cargol                 cline{4-4}
    &   &   & Vis sense fi           cline{3-4}
    &   & multirow{5}{=}{centering
                          Transforma el moviment circular en rectilini alternat o viceversa}
            & Biela-manovella        cline{4-4}
    &  &  & Lleves i excèntriques    cline{4-4}
    &  &  & Cigonyal                 hline
multirow{7}{=}{centering
                Mecanismes auxiliars}
        & multicolumn{2}{>{hsize=dimexpr2.2hsize+2tabcolsep+arrayrulewidthrelax}C|}
                      {multirow{7}{=}{Modifiquen o controlen alguns paràmetres del moviment:
                                       Gir en un sol sentit (trinquet), reduir la velocitat de
                                       gir (frens), emmagatzemar energia (molles), acoblament
                                       d'eixos i arbre de transmissió (embragatge i acoblaments)}}
            & Trinquets                      cline{4-4}
    & mcc{} & Frens                 cline{4-4}
    & mcc{} & Molles                cline{4-4}
    & mcc{} & Embragatges           cline{4-4}
    & mcc{} & Acoblaments           hline
end{tabularx}%
caption{Mecanismes}
    label{tab:mecanismes}
    end{table}
end{document}

which compilation result is:

enter image description here

Answered by Zarko on August 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