如何向該表添加另一列

如何向該表添加另一列

這是一個延續另一個問題

這是表的程式碼

\documentclass{article}
\usepackage{geometry}
  \geometry{a4paper,   % note: 'a4paper', not 'a3paper'
            showframe, % omit 'showframe' option in real document
            %total={170mm,300mm},
            %left=20mm, top=20mm,
            margin=20mm
  }
\usepackage{siunitx,booktabs}
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}
\begin{center}
\sisetup{round-mode=places,round-precision=2}
\begin{tabular}{ @{} 
                 T{1.2} 
                 *{5}{T{2.2}} 
                 S[table-format=2.3,round-precision=3] 
                 S[table-format=1.3,round-precision=3] @{} @{}}
 \toprule
 {Mass/ $m$, \unit{\kilo\gram}} &
 \multicolumn{6}{c}{Frequency/ $f$, \unit{\hertz} $\pm 0.001$} & {Tension/ $T$, \unit{\newton}} \\
 \cmidrule(lr){2-7}
 & {Trial 1} & {Trial 2} & {Trial 3} & {Trial 4} & {Trial 5} & {Average} \\
 \midrule
 0.050 & 16.200 & 16.630 & 16.560 & 16.840 & 16.550 & 16.556 & 0.491 \\
 0.100 & 23.650 & 22.800 & 22.810 & 22.970 & 22.700 & 22.986 & 0.981 \\
 0.150 & 28.060 & 27.650 & 27.600 & 27.470 & 27.440 & 26.644 & 1.472 \\
 0.200 & 34.300 & 32.030 & 32.340 & 32.380 & 32.030 & 32.616 & 1.962 \\
 0.250 & 35.500 & 35.480 & 35.420 & 35.520 & 35.350 & 35.454 & 2.453 \\
 0.300 & 38.780 & 38.820 & 38.580 & 39.000 & 38.790 & 38.794 & 2.943 \\
 0.350 & 41.800 & 42.050 & 41.750 & 41.980 & 41.950 & 41.906 & 3.434 \\
 0.400 & 44.400 & 44.760 & 44.670 & 45.020 & 44.900 & 44.750 & 3.924 \\
 0.450 & 47.450 & 47.550 & 47.520 & 47.500 & 47.650 & 47.534 & 4.415 \\
 0.500 & 50.350 & 50.190 & 49.840 & 50.170 & 49.900 & 50.090 & 4.905 \\
 \bottomrule
\end{tabular}
\end{center}

\end{document}

如何像張力柱一樣在右側添加額外的柱?

答案1

  • 在表格右側新增列很簡單,並在問題下方的評論中進行了解釋
  • 由於您說過新列與提供的 MWE 中的最後一列類似,因此只需重複此列規範並在此列中填充資料即可:
\documentclass{article}
\usepackage{geometry}
  \geometry{a4paper,
            showframe, % omit 'showframe' option in real document
            margin=20mm
  }
\usepackage{siunitx,booktabs}
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}

\begin{center}
\sisetup{round-mode=places,round-precision=2} % <-- default: rounding to 2 decimal digits
\begin{tabular}{ @{}
                 T{1.2}
                 *{5}{T{2.2}}
                      S[table-format=2.3,round-precision=3]
                 *{2}{S[table-format=1.3,round-precision=3]} @{}}
 \toprule
 {Mass/ $m$, \unit{\kilo\gram}} &
 \multicolumn{6}{c}{Frequency/ $f$, \unit{\hertz} $\pm 0.001$}                  & {Tension} & ???   \\
 \cmidrule(lr){2-7}
        & {Trial 1} & {Trial 2} & {Trial 3} & {Trial 4} & {Trial 5} & {Average} &           &       \\
 \midrule
 0.050  & 16.200    & 16.630    & 16.560    & 16.840    & 16.550    & 16.556    & 0.491     &       \\
 0.100  & 23.650    & 22.800    & 22.810    & 22.970    & 22.700    & 22.986    & 0.981     &       \\
 0.150  & 28.060    & 27.650    & 27.600    & 27.470    & 27.440    & 26.644    & 1.472     &       \\
 \bottomrule
\end{tabular}
\end{center}

\end{document}

在此輸入影像描述

)灰線顯示文字區塊邊框)

  • 或者如果您考慮我對上一個問題的回答(到目前為止您不接受收到的任何回答),則表序言中的更改為:
\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage[a4paper]{geometry}  % <---

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{center}
    \sisetup{round-mode=places,                                             % <--- added
             round-precision=2}                                             % <--- added    
\begin{tblr}{colspec = {     Q[c,si={table-format=1.2}]
                        *{5}{X[c,si={table-format=2.2}]}
                             X[c,si={table-format=2.3,round-precision=3}]   % <--- changed
                        *{2}{X[c,si={table-format=1.3,round-precision=3}]}  % <--- added specification for new column
                        },
             row{1,2} = {guard}
             }
    \toprule
\SetCell[r=2]{c} {Mass,\\ $m$ (kg)} % <--- changed
        & \SetCell[c=6]{c} Frequency, $f$ (Hz) $\pm 0.001$
                &        &        &        &        &        & \SetCell[r=2]{f} {Tension,\\ $T$ (\unit{\newton})} % <--- changed
                                                                     & \SetCell[r=2]{f} {new\\ column}  % <--- added
                                                                            \\
        \midrule
       & Trial 1& Trial 2& Trial 3& Trial 4& Trial 5& Average&       &  ??? \\
       \midrule
 0.050 & 16.200 & 16.630 & 16.560 & 16.840 & 16.550 & 16.556 & 0.491 &      \\
 0.100 & 23.650 & 22.800 & 22.810 & 22.970 & 22.700 & 22.986 & 0.981 &      \\
 0.150 & 28.060 & 27.650 & 27.600 & 27.470 & 27.440 & 26.644 & 1.472 &      \\
 0.200 & 34.300 & 32.030 & 32.340 & 32.380 & 32.030 & 32.616 & 1.962 &      \\
 0.250 & 35.500 & 35.480 & 35.420 & 35.520 & 35.350 & 35.454 & 2.453 &      \\
 0.300 & 38.780 & 38.820 & 38.580 & 39.000 & 38.790 & 38.794 & 2.943 &      \\
 0.350 & 41.800 & 42.050 & 41.750 & 41.980 & 41.950 & 41.906 & 3.434 &      \\
 0.400 & 44.400 & 44.760 & 44.670 & 45.020 & 44.900 & 44.750 & 3.924 &      \\
 0.450 & 47.450 & 47.550 & 47.520 & 47.500 & 47.650 & 47.534 & 4.415 &      \\
 0.500 & 50.350 & 50.190 & 49.840 & 50.170 & 49.900 & 50.090 & 4.905 &      \\
    \bottomrule
\end{tblr}
    \end{center}
\end{document}

在此輸入影像描述

(紅線表示文字區塊邊框)

相關內容