TeX - LaTeX Asked by harper on March 14, 2021
I know that it is not good typographical practice to add all these vertical lines to a table head. But I would like to create a substitute for and existing document and this contains these lines. I managed to create the tabular head except on vertical line:
documentclass{scrarticle}
usepackage{multirow}
%+----+------+--------------------------+---------------+
%| | | Generated by | Generated and |
%| No | Code +--------+-------+---------+ described on |
%| | | Master | Slave | Gateway | Layer |
%+----+------+--------+-------+---------+---------------+
begin{document}
begin{tabular}{|l|c|c|c|c|c|c|}
hline
multirow{3}{*}{No} &
multirow{3}{2.4cm}{Code} &
multicolumn{3}{|c|}{multirow{2}{*}{Generated by }} &
multirow{3}{2.5cm}{Generated and described on Layer}
& & multicolumn{3}{l}{} & cline{3-5}
& & Master & Slave & Gateway &
hlinehline
a & b & c & d & e & f hline
end{tabular}
end{document}
The ASCII art in the LaTeX source shows the idea of desired result. But the vertical line between column 5 and column 6 is not complete.
How can I draw this line?
Another point is that the multi-column over column 3-5 uses only one line for Master/Slave/Gateway. The separator (cline
) above should be a half line higher. This would require something like a multi-row for 1.5 lines. How can this be implemented with LaTeX?
The use of multicolumn{3}{l}{}
overwrites the vertical lines resulting in the small gap you see. Add the line back in using multicolumn{3}{l|}{}
.
documentclass{scrarticle}
usepackage{multirow}
begin{document}
begin{tabular}{|l|c|c|c|c|c|}
hline
multirow{3}{*}{No} &
multirow{3}{2.4cm}{Code} &
multicolumn{3}{|c|}{multirow{2}{*}{Generated by }} &
multirow{3}{2.5cm}{Generated and described on Layer}
& & multicolumn{3}{l|}{} & cline{3-5}
& & Master & Slave & Gateway &
hlinehline
a & b & c & d & e & f hline
end{tabular}
end{document}
Update regarding the second part of the question: In the following example, I have used a nested tabular for the "Generated by" part of the header. With this approach, I got rid of all multirow
commands. In order to make sure, teh last column's header takes up three rows, I used makecell
from the makecell
package, but you could also use a fixed width column type here. In order to make sure, the line below "Generated by" ends up higher, I used the cellspace
package, the neccessary amount of the top and bottom limit were detemined via trial and error. Lastly, I used wc
type columns from the array
package in combination with widthof
from the calc
package to make sure columns 3 to 5 have the same width as their corresponding headers:
documentclass{scrarticle}
usepackage{array}
usepackage{calc}
usepackage{makecell}
usepackage[column=0]{cellspace}
setlength{cellspacetoplimit}{6pt}
setlength{cellspacebottomlimit}{cellspacetoplimit}
begin{document}
begin{tabular}{|l|c|wc{widthof{Master}}|wc{widthof{Slave}}|wc{widthof{Gateway}}|c|}
hline
No &
Code &
multicolumn{3}{@{}c@{}|}{begin{tabular}{0c|0c|0c} multicolumn{3}{0c}{Generated by} hline Master & Slave & Gateway end{tabular} } &
makecell[cl]{Generated and described on Layer}
hlinehline
a & b & c & d & e & f hline
end{tabular}
end{document}
Correct answer by leandriis on March 14, 2021
Try this code ( usepackage{bigstrut})
begin{tabular}{|l|c|c|c|c|c|}
hline
multirow{2}[4]{*}{No}
& multirow{2}[4]{*}{Code}
& multicolumn{3}{c|}{multirow{2}[4]{*}{Generated by}}
& multicolumn{1}{p{2.5cm}|}{Generated and described on Layer}
bigstrut
hline
hline
& & Master & Slave & Gateway & bigstrut
hline
a & b & c & d & e & f bigstrut
hline
end{tabular}%
Answered by Simon Dispa on March 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP