TransWikia.com

Add a vertical line between columns

TeX - LaTeX Asked on January 14, 2021

I am creating tables for the appendix of my thesis and I have the following problems with a specific table:

  • My table starts on the next page. What should I change in the case I want my table to split in several pages?
  • I would like to add a vertical line between the second and third column (since the information presented in column 1 and 2 are the same as the information presented in column 3 and 4).

I show you the code I used and the result of it (please see that I used already newcolumntypes for other tables in the document). The table should start after appendix B.

usepackage{array,ragged2e}
newcolumntype{C}{>{Centeringhspace{0pt}}p{0.1textwidth}}
usepackage[output-decimal-marker={,}]{siunitx}

usepackage{booktabs, makecell, tabularx}
newcolumntype{L}{>{raggedrightarraybackslash}X}

newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}


section{Suppliers´ production capabilities}
begin{table}[ht]
resizebox{textwidth}{!}{%
begin{tabular}{lllll}
toprule
multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} & multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} 
midrule
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords       
Texttexttexttexttexttextt & Wordswordswordswordswordswords        
 bottomrule                                  
end{tabular}%
}
caption{Supplier facilities´ production capabilities }
label{tab:my-table}
end{table}

enter image description here

I would be extremely grateful if you can assist me with this problem!

2 Answers

Here's a longtable-based solution. All four columns allow automatic line breaking. The column widths are equal and are calculated so as to take up the maximum available width.

enter image description here

documentclass{article}
usepackage[hmargin=1in]{geometry} % set page parameters suitably
usepackage{longtable,array,ragged2e}
newlengthmylen
setlengthmylen{dimexpr0.25textwidth-1.5tabcolsep-0.25arrayrulewidthrelax}
newcolumntype{Z}{>{RaggedRight}p{mylen}}
begin{document}

section{Suppliers' production capabilities}

setlength{extrarowheight}{2pt}
begin{longtable}{@{} ZZ | ZZ @{}}

%%% headers and footers:

caption{Supplier facilities' production capabilities }
label{tab:my-table}
hline
textbf{Facility Name} & textbf{Product} & 
textbf{Facility Name} & textbf{Product} 
hline
endfirsthead

multicolumn{4}{@{}l}{Table thetable, cont'd}[1ex]
hline
textbf{Facility Name} & textbf{Product} & 
textbf{Facility Name} & textbf{Product} 
hline
endhead

hline
multicolumn{4}{r@{}}{footnotesize cont'd on following page}
endfoot

hline
endlastfoot

%%% Body of table

Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords 
end{longtable}
end{document}

Correct answer by Mico on January 14, 2021

Here is how to use xltabular – it's the same syntax as for longtable, except you declare the total width. In particular, in a longtable, you don't use the table environment (it is not a float), the caption is incorporated to the table, in the firsthead section.

    documentclass{article}
    usepackage{array,ragged2e}
newcolumntype{C}{>{Centeringhspace{0pt}}p{0.1textwidth}}
usepackage[output-decimal-marker={,}]{siunitx}
usepackage{lipsum}
usepackage{booktabs, makecell, xltabular}
newcolumntype{L}{>{raggedrightarraybackslash}X}

newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}


begin{document}

section{Suppliers´ production capabilities}
lipsum[1-3]

begin{xltabular}{textwidth}{*{4}{L}}
caption{Supplier facilities´ production capabilities }
label{tab:my-table} 
toprule
multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} & multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} 
midrule
endfirsthead
{footnotesize (Continued)}
toprule
multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} & multicolumn{1}{c}{textbf{Facility Name}} & multicolumn{1}{c}{textbf{Product}} 
midrule
endhead
midrule
multicolumn{4}{r}{footnotesize (to be continued)}
endfoot
bottomrule
endlastfoot
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words  addlinespace
Text text text text text textt & Words words words words words words 
end{xltabular}%

end{document} 

enter image description here

Answered by Bernard on January 14, 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