TransWikia.com

Vertical lines in table do not match

TeX - LaTeX Asked by Aqib on June 24, 2021

I want to typeset the following table with vertical lines but some lines are not matching.

documentclass{article}
usepackage{multirow}
usepackage{changepage}
usepackage{array}
usepackage{romannum}
usepackage{rotating}
usepackage{calc}
usepackage{amsmath}
usepackage{makecell}
usepackage{nicematrix}
usepackage{tabu}
newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}
newcolumntype{M}[1]{>{centeringarraybackslash}m{#1}}

begin{document}
%begin{table}[h!]
begin{sidewaystable}[h!]
%begin{adjustwidth}{-4.5cm}{}
    
begin{tabular}{|c|c|c|c|c|c|c|}
     
hline
multicolumn{7}{|l|}{My name is Tam Sam Insti}
multicolumn{7}{|l|}{}

hline
multicolumn{4}{|l|}{} & multicolumn{2}{l|}{multirow{2}{4cm}{}} &
multicolumn{4}{|l|}{aarival} & multicolumn{2}{l|}{multirow{2}{4cm}{Departure}} &   cline{1-4}
multicolumn{4}{|l|}{} & multicolumn{2}{l|}{multirow{2}{4cm}{}} & 




multicolumn{2}{|l}{Train Number} & multicolumn{2}{|l|}{Station }&&&   cline{1-6}
multicolumn{2}{|l|}{} & multicolumn{2}{l|}{} &&& 


&&&&&& multirow{2}{4.1cm}{}
9.00 & 10.00 & 11.00 &12.00&13.00&14.00& multirow{2}{4.1cm}{9.00} 
&&&&&&
&&&&&& multirow{2}{4.1cm}{}
hline
&&&&&&

papri& nain & good & mrth & monday & tuesday & saturday 
&&&&&&
hline
 end{tabular}
  
%end{adjustwidth}
%end{table}
end{sidewaystable}
end{document}

enter image description here

4 Answers

Is the line between 'Train Number' and 'Station' the one you wanted to align differently?

enter image description here

documentclass{article}
usepackage{multirow}
usepackage{changepage}
usepackage{array}
usepackage{romannum}
usepackage{rotating}
usepackage{calc}
usepackage{amsmath}
usepackage{makecell}
usepackage{nicematrix}
usepackage{tabu}
newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}
newcolumntype{M}[1]{>{centeringarraybackslash}m{#1}}

begin{document}
    %begin{table}[h!]
    begin{sidewaystable}[h!]
        %begin{adjustwidth}{-4.5cm}{}
        
        begin{tabular}{|c|c|c|c|c|c|c|}
            
            hline
            multicolumn{7}{|l|}{My name is Tam Sam Insti}
            multicolumn{7}{|l|}{}
            
            hline
            multicolumn{4}{|l|}{} & multicolumn{2}{l|}{multirow{2}{4cm}{}} &
            multicolumn{4}{|l|}{aarival} & multicolumn{2}{l|}{multirow{2}{4cm}{Departure}} &   cline{1-4}
            multicolumn{4}{|l|}{} & multicolumn{2}{l|}{multirow{2}{4cm}{}} & 
            
            
            
            
            multicolumn{2}{|l|}{Train Number} & multicolumn{2}{l|}{Station }&multicolumn{2}{l|}{}&   cline{1-6}
            &&& &&& 
            
            
            &&&&&& multirow{2}{4.1cm}{}
            9.00 & 10.00 & 11.00 &12.00&13.00&14.00& multirow{2}{4.1cm}{9.00} 
            &&&&&&
            &&&&&& multirow{2}{4.1cm}{}
            hline
            &&&&&&
            
            papri& nain & good & mrth & monday & tuesday & saturday 
            &&&&&&
            hline
        end{tabular}
        
        %end{adjustwidth}
        %end{table}
    end{sidewaystable}
end{document}

Correct answer by schoekling on June 24, 2021

enter image description here

documentclass{article}
usepackage{multirow}
usepackage{booktabs}
%usepackage{changepage}
%usepackage{array}
%usepackage{romannum}
%usepackage{rotating}
%usepackage{calc}
%usepackage{amsmath}
%usepackage{makecell}
%usepackage{nicematrix}
%usepackage{tabu}
%newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}
%newcolumntype{M}[1]{>{centeringarraybackslash}m{#1}}

begin{document}
    begin{table}[h!]
        begin{tabular}{ccccccc}
            toprule
            multicolumn{7}{l}{My name is Tam Sam Insti}
            midrule
            multicolumn{4}{l}{Arrival} & multicolumn{3}{l}{Departure}   cmidrule{1-6}
            multicolumn{4}{l}{Train Number} & multicolumn{3}{l}{Station }   cmidrule{1-6}
            9.00 & 10.00 & 11.00 &12.00&13.00&14.00&  
            midrule
            &&&&&&multirow{1.4}{*}{9.00}midrule
            papri& nain & good & mrth & monday & tuesday & saturday 
            bottomrule
        end{tabular}
    end{table}
end{document}

EDIT for line vertical

change the following line

    multicolumn{4}{l|}{Train Number} & multicolumn{3}{l}{Station }   cline{1-6}

enter image description here

Answered by js bibra on June 24, 2021

It is entirely clear what is your problem. So I mostly try to clean-up your code try (based on guessing) to make more logical layout:

documentclass{article}
usepackage[strict]{changepage}
usepackage{rotating}
usepackage{array, makecell, multirow, tabularx}
newcolumntype{C}{>{centeringarraybackslash}X}
NewExpandableDocumentCommandmcl{O{|c|}m}{multicolumn{#1}{|l|}{#2}}
NewExpandableDocumentCommandmcll{O{|c|}m}{multicolumn{#1}{l|}{#2}}

%---------------- Show page layout. Don't use in a real document!
usepackage{showframe}
renewcommandShowFrameLinethickness{0.15pt}
renewcommand*ShowFrameColor{color{red}}
%---------------------------------------------------------------%

begin{document}
    begin{adjustwidth}{}{-dimexprmarginparwidth+marginparsep}
    setcellgapes{7pt}
    makegapedcells
begin{tabularx}{linewidth}{|*{4}{>{centering}p{4em}|}C|C|C|}
    Xhline{1.2pt}
mcl[7]{My name: textbf{Tam Sam Insti}}           
    hline
mcl[4]{Arival}         & mcll[2]{Departure}    &           
    cline{1-6}
mcl[2]{Train Number}   & mcll[2]{Station}      &   &   &    
    cline{1-6}
9.00 & 10.00 & 11.00 & 12.00 & 13.00 & 14.00 & 9.00         
    hline
papri& nain & good & mrth & monday & tuesday & saturday 
    Xhline{1.2pt}
    end{tabularx}
    end{adjustwidth}
end{document}

which now gives:

enter image description here

(red lines indicate page layout)

Answered by Zarko on June 24, 2021

Here is a solution with {NiceTabular} of nicematrix.

 documentclass{article}
 usepackage{nicematrix}
 usepackage{rotating}

 begin{document}

 renewcommand{arraystretch}{1.4}
 begin{sidewaystable}
 begin{NiceTabular}{*{4}{c}ccw{c}{4cm}}[hvlines]
 Block[l]{1-*}{My name is Tam Sam Insti} 
 Block[l]{1-4}{aarival} &&&& Block[l]{2-2}{Departure} && Block{3-1}{}
 Block[l]{1-2}{Train number} && Block[l]{1-2}{Station} 
 rule[-5mm]{0pt}{10mm}%
 9.00 & 10.00 & 11.00 & 12.00 & 13.00 & 14.00 & Block[l]{1-1}{9.00}  
 papri & nain & good & mrth & monday & thesday & saturday 
 end{NiceTabular}
 end{sidewaystable}

 end{document}

Outputo of the above code

Answered by F. Pantigny on June 24, 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