3

Probably a question that has appeared somewhere before, but I have not found a comprehensive solution to it yet. How to create a table with custom row height (eg. 5cm), vertical center and horizontal center. Thank you very much!

enter image description here

P/S: I used to use \newcolumntype but I can only modify the attributes of column:

example:

\documentclass{article}

\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{tabular}{| c | L{3cm} | C{3cm} | R{3cm} |}

content

\end{tabular}

\end{document}
1
  • it would be great if you share your code for the above table--punching data is tedious
    – js bibra
    Commented Dec 4, 2021 at 4:12

2 Answers 2

6

Just table, without symbols at bottom right corners of headers cells, with tabularray package too. From interesting @Imran answer (+1) it differ in:

  • table design
  • a way how table specifications are determined
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\noindent%
\begin{tblr}{hline{1,Z}=1pt, hline{2}=0.6pt, hline{3-Y}=0.2pt,
             vlines,
             rows = {4\baselineskip, font=\sffamily},
             row{1} = {bg=azure8, fg=white, font=\bfseries},
             colspec = {X[1,c] X[2,l] X[4,l] X[2,c, si={table-format=3.0}]},
            }
Order   & Date  & Product           & {{{Qty}}} \\
%
1001    & 1-May & Arrowroot         &   5       \\
1002    & 2-May & Bran              &  20       \\
1003    & 3-May & Chocolate Chip    &  80       \\
1004    & 4-May & Oatmeal Raisin    & 240       \\
\end{tblr}
\end{document}

enter image description here

Edit: It is not clear, what you mean with atribute. A symbols at bottom right corners of headers cells? It is possible to drawn it in cells, but achieve their functionality (for example: open windows, where you can select contents in cells) is a different story. For this LaTeX is not right tools.

Addendum (1): In the case that you like to have a long table caption and column headers on each page, that you should use longtblr anvironment:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\DefTblrTemplate{contfoot-text}{normal}{\scriptsize\textit{Continued on the next page}}
\SetTblrTemplate{contfoot-text}{normal}
\noindent%
\begin{longtblr}[
caption = {Caption text if any (caption label is always presented)},
  label = {tab:lontblr}
                ]{
        rowhead=1,
        hline{1,Z}=1pt, hline{2}=0.6pt, hline{3-Y}=0.2pt,
        vlines,
        rows = {4\baselineskip, font=\sffamily},
        row{1} = {bg=azure8, fg=white, font=\bfseries},
        colspec = {X[1,c] X[2,l] X[4,l] X[2,c, si={table-format=3.0}]},
            }
Order   & Date  & Product           & {{{Qty}}} \\
%
1001    & 1-May & Arrowroot         &   5       \\
1002    & 2-May & Bran              &  20       \\
1003    & 3-May & Chocolate Chip    &  80       \\
1004    & 4-May & Oatmeal Raisin    & 240       \\
%
1001    & 1-May & Arrowroot         &   5       \\
1002    & 2-May & Bran              &  20       \\
1003    & 3-May & Chocolate Chip    &  80       \\
1004    & 4-May & Oatmeal Raisin    & 240       \\
%
1001    & 1-May & Arrowroot         &   5       \\
1002    & 2-May & Bran              &  20       \\
1003    & 3-May & Chocolate Chip    &  80       \\
1004    & 4-May & Oatmeal Raisin    & 240       \\
%
1001    & 1-May & Arrowroot         &   5       \\
1002    & 2-May & Bran              &  20       \\
1003    & 3-May & Chocolate Chip    &  80       \\
1004    & 4-May & Oatmeal Raisin    & 240       \\
\end{longtblr}
\end{document}

enter image description here

Addendum (2): In the case, when you not like to have captions, than before table add:

\DefTblrTemplate{firsthead, middlehead,lasthead}{default}{}

and than delete optional table specifications (since they haven't any sence anymore). So, complete table specifications in your case are:

\begin{longtblr}{
        rowhead={1},
        hline{1,Z}=1pt, hline{2}=0.6pt, hline{3-Y}=0.2pt,
        vlines,
        rows = {4\baselineskip, font=\sffamily},
        row{1} = {bg=azure8, fg=white, font=\bfseries},
        colspec = {X[1,c] X[2,l] X[4,l] X[2,c, si={table-format=3.0}]},
            }
2
  • That's what I looking for, but when my table is too long, tabularry package seem can't not stretch table over pages, can you help me with this problem?
    – tungsondkh
    Commented Dec 5, 2021 at 8:59
  • 1
    @tungsondkh, but you accept other answer :-). I suppose that this comment is intendent for it. BTW, requirement for long table is not present in your question. And yes, tabularray package support long tables: use longtblr and its options.
    – Zarko
    Commented Dec 5, 2021 at 9:03
5

You can do it with the tabularray package.

MWE:

\documentclass{article}

\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hlines,vlines,
rows = {2.5cm, c},
row{1} = {bg=azure7, fg=white},
column{1} = {1cm, c},
column{2, 4} = {2cm, c},
column{3} = {3cm, c},
}

Order & Date & Product & Qty\\
1001 & 11/11 & Asdf & 50\\
\end{tblr}

\end{document}

output

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .