4

tabularray is quite useful as I need to do these things:

  1. Keep the table as wide as \textwidth
  2. I need to insert note{} in the caption of the table
  3. The head of the table are two many characters, so they are divided into several lines in one cell. In this case, I need to keep short heads to be the middle of the cell of the table
  4. Keep the number decimal aligned

As I know:

  • To achieve 1, I can use tblr or talltblr with X format
  • To achieve 2, I need use talltblr
  • To achieve 4, I can use talltblr with X and si={}

But, how can I achieve 3 by talltblr? If we can merge Q format into talltblr, these four functions could be achieved at the same time.

For example:

\documentclass{article}

\usepackage{tabularray} \usepackage{siunitx} \usepackage{romannum} \UseTblrLibrary{booktabs, siunitx} \begin{document} \begin{table}[h] \begin{talltblr} [caption={Main component geographic information table\TblrNote{1}}, label={tab:Main component geographic information table}, note{1}={The data is obtained through satellite maps, and there are certain errors}, note{2}={The latitude and longitude of the surface is the latitude and longitude of its centroid. There is a certain error in the measurement of latitude and longitude, for reference}, note{3}={This length is the length in our study area} ] {colspec={ X[1.5,r] X[1.3,c] X[1.3,c] X[c,si={table-format=4.2},0.8] X[c,si={table-format=4.2},0.8] X[c,si={table-format=1.2},0.8] } } \toprule name & latitude\TblrNote{2} & longitude &{gggggg\unit{\m}} & gggggg\unit{\m} \TblrNote{3} &{{{area total\unit{\km\squared}}}}\

     \midrule
  DongLake      &\ang{30;33;29.52}N &\ang{114;22;47.55}E &             &         & 12.74 \\
  dongtinglake     &\ang{30;33;12.71}N &\ang{114;20;46.87}E &         &         &0.12 \\
  great river      &\ang{30;33;33.66}N &\ang[minimum-integer-digits=2]{114;20;09.29}E & 1682.88&         &        \\
 bigbig lake      &\ang[minimum-integer-digits=2]{30;34;06.02}N &\ang{114;19;45.86}E &         &         & 2.74    \\
 inside the gate   &\ang{30;33;54.85}N &\ang{114;18;35.99}E &         &         & 0.06  \\
  new ditches     &\ang{30;35;33.19}N &\ang[minimum-integer-digits=2]{114;23;02.77}E & 977    &         &         \\
  west part of new gate   &\ang{30;35;26.31}N &\ang{114;21;43.67}E & 5213.77 &         &         \\
 luoai port   &\ang[minimum-integer-digits=2]{30;37;08.49}N &\ang{114;21;27.93}E & 3770.58 &         &         \\

qingling port &\ang[minimum-integer-digits=2]{30;39;02.32}N &\ang{114;24;30.27}E & & & 0.13 \ from port to lake &\ang[minimum-integer-digits=2]{30;37;03.06}N &\ang{114;24;22.99}E & 345.15 & & \ east part of the gate &\ang[minimum-integer-digits=2]{30;38;05.41}N &\ang{114;24;27.64}E &2926.08 & & \ Yangzi river &\ang{30;37;43.29}N &\ang{114;20;58.87}E & & & \ east part of the lake &\ang{30;35;55.14}N &\ang{114;23;14.49}E & 1090.45 & & \ donghu port &\ang{30;35;37.38}N &\ang{114;23;45.81}E & 7332.3 & \num{4614.19} & \ west section of qingqing &\ang[minimum-integer-digits=2]{30;38;01.20}N &\ang{114;24;11.10}E & 3449.86 & & \ new road drainage station &\ang{30;33;55.17}N &\ang{114;18;48.14}E & & & \ nanjing drainage station &\ang{30;33;52.23}N &\ang{114;18;29.72}E & & & \ beijing pumping station &\ang{30;37;22.34}N &\ang[minimum-integer-digits=2]{114;21;01.01}E & & & \ guilin road gata &\ang{30;37;19.42}N &\ang{114;20;57.23}E & & & \ the last gate &\ang{30;39;16.08}N &\ang{114;24;31.97}E & & & \
\bottomrule \end{talltblr} \end{table} \end{document}

How to make this table to achieve the four requests? enter image description here

Another question: why can't I replace gggggg with Length? When I did this, there is error: Package siunitx Error: Invalid number 'e'.

Y. zeng
  • 1,885
  • 3
    All this (except Q column) contain my answer on your previous question. Beside this, all this is thoroughly described with many examples in the package documentation (it is part of its installation, available is also on CTAN). – Zarko Apr 13 '22 at 08:17
  • @Zarko Hello, I checked the file: https://texdoc.org/serve/tabularray/0. I didn't find a way to merge Q, X and si into talltablr. At this time, I know how to merge X and si into talltablr from your previous answer. Q can adjust columns and rows style. – Y. zeng Apr 13 '22 at 08:22
  • 2
    An X column is just Q[co=1]... – Paul Gaborit Apr 13 '22 at 08:31
  • @PaulGaborit May you tell me the reason? – Y. zeng Apr 13 '22 at 08:32
  • 1
    In tabularray.sty, you find the definition of X: \NewColumnRowType{X}[1][]{Q[co=1,#1] }. – Paul Gaborit Apr 13 '22 at 08:41
  • @PaulGaborit I never make a new command before. What does this mean and how to use it? – Y. zeng Apr 13 '22 at 08:45
  • I have package documentation ... I don't see any sense to write you general answer by copying text from it to an answer. Please provide an example, what you like to achieve. For example colspec = {r Q[l,m] X[1,h,j] X[2,h,j] Q[l,m]} should works out of the box. Table will has \textwidth width due to used X columns. For more, let me repeat myself, please provide an MWE, that we can see, what you like to have. – Zarko Apr 13 '22 at 09:32
  • @Zarko Thanks for your reminder. I modified my post. If you have time, please guide me. – Y. zeng Apr 13 '22 at 10:23

1 Answers1

6

Edit: ups, I didn't upload the last version of code and image. Corrected now. So4ry for noise ...

As starting point:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx} % libraries loads packages of the same names

\begin{document} \begin{table}[h] \sisetup{minimum-integer-digits=2} \begin{talltblr}[ caption = {Main component geographic information table}, label = {tab:Main component geographic information table}, remark{Note} = {The data are obtained through satellite maps, and there are certain errors}, note{1} = {The latitude and longitude of the surface is the latitude and longitude of its centroid. There is a certain error in the measurement of latitude and longitude, for reference}, note{2} = {This length is the length in our study area}, note{3} = {Total area} ]{colsep = 3pt, colspec = {@{} X[2,l, m, font=\linespread{0.84}\selectfont] r r *{2}{X[c, si={table-format=4.2}]} X[c, si={table-format=2.2, minimum-integer-digits=1}] @{}}, row{1} = {font=\small\bfseries, c, m} } \toprule name & latitude\TblrNote{1} & longitude & {{{gggggg \unit{\metre}}}} & {{{gggggg\TblrNote{2} \unit{\metre}}}} & {{{area\TblrNote{3} \unit{\km\squared}}}}\

\midrule

Dong Lake & \ang{30;33;29.52}N & \ang{114;22;47.55}E & & & 12.74 \ Dongting Lake
& \ang{30;33;12.71}N &\ang{114;20;46.87}E & & & 0.12 \ Great river & \ang{30;33;33.66}N & \ang{114;20;09.29}E
& 1682.88 & & \ Big lake & \ang{30;34;06.02}N
& \ang{114;19;45.86}E & & & 2.74 \ inside the gate
& \ang{30;33;54.85}N & \ang{114;18;35.99}E & & & 2.74 \ new ditches & \ang{30;35;33.19}N
&\ang{114;23;02.77}E & 977
& & \ west part of new gate
& \ang{30;35;26.31}N & \ang{114;21;43.67}E & 5213.77 & & \ Luoai port & \ang{30;37;08.49}N
&\ang{114;21;27.93}E & 3770.58 & & \ qingling port
& \ang{30;39;02.32}N
&\ang{114;24;30.27}E & & & 0.13 \ from port to lake & \ang{30;37;03.06}N
& \ang{114;24;22.99}E & 345.15 & & \ east part of the gate
& \ang{30;38;05.41}N
& \ang{114;24;27.64}E & 2926.08 & & \ Yangzi river
& \ang{30;37;43.29}N & \ang{114;20;58.87}E & & & \ east part of the lake
& \ang{30;35;55.14}N & \ang{114;23;14.49}E & 1090.45 & & \ Donghu port & \ang{30;35;37.38}N & \ang{114;23;45.81}E & 7332.3 & 4614.19 & \ west section of qingqing
& \ang{30;38;01.20}N
& \ang{114;24;11.10}E & 3449.86 & & \ new road drainage station & \ang{30;33;55.17}N &\ang{114;18;48.14}E & & & \ nanjing drainage station
& \ang{30;33;52.23}N & \ang{114;18;29.72}E & & & \ Beijing pumping station
& \ang{30;37;22.34}N &\ang{114;21;01.01}E
& & & \ Guilin road gata
& \ang{30;37;19.42}N &\ang{114;20;57.23}E & & & \ the last gate
& \ang{30;39;16.08}N & \ang{114;24;31.97}E & & & \ \bottomrule \end{talltblr} \end{table} \end{document}

enter image description here

Notes: You really read (again and again) package documentation. Not just read but also experimenting with different settings for column formatting. My experiences show me, that the best metod of learning is learning-by-doing. At start is a bit time consuming, but you will quite soon figured out philosophy of tabularray syntax.

  • Meaning of options c (center), l (left), r (right) and m (middle), t (top) b (bottom, last three are defined in the array package) is the same as at classic tables. - Beside mentioned options, tabularray introduce three more options: h (head, at top of cell), f (foot, at bottom of cell) and j (justified).
  • This options can be used stand alone or as attributes of X or Q columns types. For example:
    • X[c] has width, which is calculated by LaTeX and column content is horizontal
    • `X[2,l] has twice of width, which is calculated by LaTeX and left aligned column content
    • Q[c, 2cm] or Q[c, wd=2cm] define column with 2cm width and horizonal centered content
    • X[j] has justified text, which is hyphenated when needed
    • column c behave the same as at "classic" tables width of column is equal to the width of longest content in cells and is horizontal centered (similarly is for other options)
  • At S columns (define as S column or for example Q[c, si], where formatting can be defined by \sisetup outside of table, see siunitx documentation) the no number content of such cel had to be according siunitx package in classic tables enclosed in pair of curly braces:
    • by this is interrupted table-format settings,
    • disabled wrong interpretation of content meaning (bear in mind, that siunitx use some letters for designate numbers, for example 10e5 mean 10 x 10^5!
  • The tabularray due to different table processing (using l3exp) require to add two more curly braces pairs (that siunitx requirement works in all circumstances).
  • The tabularray package enables formatting rows to. For examples:
    • with row{1} = {font=\bfseries} prescribe boldface text in all row cells in the first row,
    • with row{Z} = {font=\scfaily, c} prescribe small caps font and centering of contents in the last row in table
  • etc.,

Addendum: you may liked table formatting, which groups rows, for example with three of them and insert some additional vertical space between them. For this add to preamble

  \ExplSyntaxOn
\NewChildSelector{eachthree}
  {
    \int_step_inline:nnnn {5}{3}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

and to table preamble:

                   row{eachthree} = {abovesep=2ex},

Considering this additions, table will los as follow:

enter image description here

Zarko
  • 296,517
  • Hello, Thanks for your reply. What's the meaning of 2 in X[2,l, m, font=\linespread{0.84}\selectfont]? – Y. zeng Apr 13 '22 at 13:04
  • Which codes made the units of columns 4, 5 and 6 not bold and become the second row? Can't the font modifie the siunitx? Am I right? – Y. zeng Apr 13 '22 at 13:13
  • Why will changing {{{gggggg \unit{\metre}}}} to {{{ gggggg\unit{\metre}}}} make it one line? What's the meaning of blank in the {{{gggggg \unit{\metre}}}} ? – Y. zeng Apr 13 '22 at 13:23
  • 1
    Please, red package documentation. Answers on all your question you will find in it. :-). X[2, ...] means that column width is 2 x width column if it will be just X[...]. Column headers should not be wider than column width, so it is advisable to enable that it can be split in two (or more) lines when needed. In addition, the meaning of the text becomes meaningful. You can set all table to smaller font if you put \small directive after \begin{table}. – Zarko Apr 13 '22 at 13:33
  • I can't understand the package documentation very well. Maybe for my poor English or for my poor LaTeX skill. Is the blank advisable to enable it can be split into two lines? Why didn't you use c c in X[2,l, m, font=\linespread{0.84}\selectfont] r r? I tested c c and it is not right. But I don't know the reason. Why did the r r make blank between columns? – Y. zeng Apr 13 '22 at 13:39
  • Why are there error when changing {{{gggggg \unit{\metre}}}} to Length \unit{\metre}? – Y. zeng Apr 13 '22 at 14:03
  • Because not number cell content had to be enclosed with three curly braces pairs (you not believe documentation nor my comments at your previous question :-( ) – Zarko Apr 13 '22 at 14:08
  • Okay. I know now. Why didn't you use c c in X[2,l, m, font=\linespread{0.84}\selectfont] r r? I tested X[2,l, m, font=\linespread{0.84}\selectfont] c c and it is not right. But I don't know the reason. Why did the r r make blank between columns? – Y. zeng Apr 13 '22 at 14:13
  • @Y.zeng, see notes to answer. r column type doesn't make anything blank. If some cell is empty, than you not write any content in it. – Zarko Apr 13 '22 at 15:36
  • Thank you very much for your patient explanation. I understand 2/3. In the future, I will read the document again and again with doing it at the same time. Have a nice day ahead! – Y. zeng Apr 13 '22 at 15:57
  • Hello, does colsep = 3pt set each default column width to 3pt? How should I know how many "pts" of \textwitdth? – Y. zeng Apr 15 '22 at 02:16
  • @Y.zeng, of colsep (it is equivalent to \tabcolsep in classic tables) is minimal horizontal distance between cell content and cell border. It default value is 6 pt (pints). – Zarko Apr 15 '22 at 04:28
  • Why did you set this colsep = 3pt? – Y. zeng Apr 15 '22 at 07:03
  • @Y.zeng, remove it and than see the difference :-). That can be put wider text into cells. – Zarko Apr 15 '22 at 07:26
  • Why didn't set it to 0? I removed it and found the fourth column is under below others. It is a little weird. – Y. zeng Apr 15 '22 at 07:37
  • @Y.zeng, that is matter of personal preference (opinion based). – Zarko Apr 15 '22 at 07:56
  • I removed colsep = 3pt and found the fourth column is below others. Why? – Y. zeng Apr 15 '22 at 08:01