TransWikia.com

Move table to the right

TeX - LaTeX Asked by bLAZ on December 5, 2020

Is it possible to align table to the right?

I tried hfill, but seems not working with the tables:

hfillbegin{table}[h]
begin{tabular}[t]{l|c|l|c|c|}
cline{2-5}
Zestawienie VAT: & cellcolor[HTML]{C0C0C0}textbf{begin{tabular}[c]{@{}c@{}}Wartość netto {[}zł{]}end{tabular}} & multicolumn{1}{c|}{cellcolor[HTML]{C0C0C0}textbf{begin{tabular}[c]{@{}c@{}}Stawka VATend{tabular}}} & cellcolor[HTML]{C0C0C0}textbf{begin{tabular}[c]{@{}c@{}}Wartość VAT {[}zł{]}end{tabular}} & cellcolor[HTML]{C0C0C0}textbf{begin{tabular}[c]{@{}c@{}}Wartość brutto {[}zł{]}end{tabular}}  cline{2-5} 
                 & multicolumn{1}{r|}{}                                                                             & zw                                                                                                         & multicolumn{1}{r|}{0,00}                                                                       & multicolumn{1}{r|}{}                                                                               cline{2-5} 
end{tabular}
end{table}

2 Answers

Just insert the raggedleft directive inside the table environment. I took the opportunity to simplify the code of your tabular, in particular replacing the nested tabulars with the simpler Centerstack from stackengine and using rowcolor at the beginning of the fist row.

documentclass[table]{article}
usepackage[T1]{fontenc}
usepackage[usestackEOL]{stackengine}
usepackage{showframe}
renewcommand{ShowFrameLinethickness}{0.2pt}
usepackage{xcolor} 

begin{document}

begin{table}[h]
raggedleftbegin{tabular}[t]{l|c|l|c|c|}
cline{2-5}
rowcolor[HTML]{C0C0C0}cellcolor{white}Zestawienie VAT: & bfseriesCenterstack{Wartość netto [zł]} & bfseriesCenterstack{Stawka VAT} & bfseriesCenterstack{Wartość VAT [zł]} & bfseriesCenterstack{Wartość brutto [zł]}  cline{2-5}
                 & & zw & multicolumn{1}{r|}{0,00} &  cline{2-5}
end{tabular}
end{table}

end{document} 

enter image description here

Answered by Bernard on December 5, 2020

Edit:

  • IN colored cells are beter seen horizontal lines defined by hhline package, so instead of cline{2-3} is better to use hhline{~|----|}.
  • Below are two examples of your table. However, I wonder why you have cells in the first column without border. Since the context of this is unknown it seems quite strange ...
documentclass{article}
usepackage{geometry}
usepackage[table]{xcolor}
usepackage{array, hhline}
newcommandMakeCell[1]{begin{tabular}{@{} >{bfseriessmall}c @{}}#1end{tabular}}
usepackage{siunitx}

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

begin{document}
    begin{table}[ht]
    centering
    setlengthextrarowheight{2pt}
begin{tabular}[t]{l|*{4}{S[table-format=2.2]|}}
    hhline{~|----|}
Zestawienie VAT:    & cellcolor{gray!50}{MakeCell{Wartość netto [zł]}} 
                        & cellcolor{gray!50}{MakeCell{Stawka VAT}} 
                            & cellcolor{gray!50}{MakeCell{Wartość VAT [zł]}} 
                                & cellcolor{gray!50}{MakeCell{Wartość brutto [zł]}} 
                                         
    hhline{~|----|}
                    &  & {zw}                                                                                                         
                            & 0.00
                                &       
    hhline{~|----|}
end{tabular}
    end{table}
or
    begin{table}[ht]
    raggedleft
    setlengthextrarowheight{2pt}
begin{tabular}[t]{l|*{4}{S[table-format=2.2]|}}
    hhline{~|----|}
Zestawienie VAT:    & cellcolor{gray!50}{MakeCell{Wartość netto [zł]}}
                        & cellcolor{gray!50}{MakeCell{Stawka VAT}}
                            & cellcolor{gray!50}{MakeCell{Wartość VAT [zł]}}
                                & cellcolor{gray!50}{MakeCell{Wartość brutto [zł]}}
                                        
    hhline{~|----|}
                    &  & {zw}
                            & 0.00
                                &       
    hhline{~|----|}
end{tabular}
    end{table}    
end{document}

gives:

enter image description here

Answered by Zarko on December 5, 2020

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