如何使数学符号在表格中居中?

如何使数学符号在表格中居中?

我想让箭头和 \vdots 居中,但不知道该怎么做。我想创建一个图形,但我认为最聪明的方法是将其创建为表格。任何帮助都将不胜感激!(附加问题:如何让“Cal-23”居中?)。

\documentclass[12pt]{book}

\usepackage[]{graphicx}
\usepackage[]{color}
\usepackage{alltt}

\usepackage[a4paper, width = 160mm, top = 35mm, bottom = 30mm, 
bindingoffset = 0mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{tabularray}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering
\begin{tblr}{
  cell{1}{6} = {c=2}{},
  vline{1,13} = {1}{},
  vline{1,4,7,10,13} = {3}{},
  vline{1-4,7,10,13} = {5}{},
  vline{4-7,10,13} = {7}{},
  hline{1-8} = {-}{},
  hspan = even,
}
       &        &        &        &        & Cal-23  &  &        &  &  &        &  \\
       & $\downarrow$  &        &        & $\downarrow$  &         &  & $\downarrow$  &  &  & $\downarrow$  &  \\
       & Q1/23  &        &        & Q2/23  &         &  & Q3/23  &  &  & Q4/23  &  \\
$\downarrow$  & $\downarrow$  & $\downarrow$  &        & $\downarrow$  &         &  & $\downarrow$  &  &  & $\downarrow$  &  \\
Jan/23 & Feb/23 & Mar/23 &        & Q2/23  &         &  & Q3/23  &  &  & Q4/23  &  \\
       &        &        & $\downarrow$  & $\downarrow$  & $\downarrow$   &  & $\downarrow$  &  &  & $\downarrow$  &  \\
       &        &        & Apr/23 & May/23 & Jun/23 &  & Q3/23  &  &  & Q4/23  &  \\
       &        &        &        &        &         & $\vdots$ & $\vdots$ & $\vdots$ &  & $\vdots$ &  
\end{tblr}
\end{table}

\end{document}

在此处输入图片描述

答案1

  • 你可以用例如将所有单元格居中cells={halign=c}

  • 要使其居中Cal-23,可以将其放置在列中间的单元格中,或者将此行中的所有单元格合并在一起:


\documentclass[12pt]{book}

\usepackage[]{graphicx}
\usepackage[]{color}
\usepackage{alltt}

\usepackage[a4paper, width = 160mm, top = 35mm, bottom = 30mm, 
bindingoffset = 0mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{tabularray}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering
\begin{tblr}{
  cell{1}{6} = {c=2}{},
  vline{1,13} = {1}{},
  vline{1,4,7,10,13} = {3}{},
  vline{1-4,7,10,13} = {5}{},
  vline{4-7,10,13} = {7}{},
  hline{1-8} = {-}{},
  hspan = even,
  cells={halign=c}
}
       \SetCell[c=12]{} Cal-23 &        &        &        &        &   &  &        &  &  &        &  \\
       & $\downarrow$  &        &        & $\downarrow$  &         &  & $\downarrow$  &  &  & $\downarrow$  &  \\
       & Q1/23  &        &        & Q2/23  &         &  & Q3/23  &  &  & Q4/23  &  \\
$\downarrow$  & $\downarrow$  & $\downarrow$  &        & $\downarrow$  &         &  & $\downarrow$  &  &  & $\downarrow$  &  \\
Jan/23 & Feb/23 & Mar/23 &        & Q2/23  &         &  & Q3/23  &  &  & Q4/23  &  \\
       &        &        & $\downarrow$  & $\downarrow$  & $\downarrow$   &  & $\downarrow$  &  &  & $\downarrow$  &  \\
       &        &        & Apr/23 & May/23 & Jun/23 &  & Q3/23  &  &  & Q4/23  &  \\
       &        &        &        &        &         & $\vdots$ & $\vdots$ & $\vdots$ &  & $\vdots$ &  
\end{tblr}
\end{table}

\end{document}

在此处输入图片描述

答案2

MMM/23 标签无法容纳行宽的十二分之一,因此无法获得十二列的相同大小。

\documentclass[12pt]{book}
\usepackage[
  a4paper,
  width = 160mm,
  top = 35mm,
  bottom = 30mm, 
  bindingoffset = 0mm,
]{geometry}
\usepackage{array}

\begin{document}

\begin{table}[htp]

\setlength{\tabcolsep}{0pt}

\begin{tabular}{*{12}{w{c}{\dimeval{(\textwidth-7\arrayrulewidth)/12}}}}
\hline
\multicolumn{12}{|c|}{Cal-23} \\
\hline
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} \\
\hline
\multicolumn{3}{|c|}{Q1/23} &
\multicolumn{3}{c|}{Q2/23} &
\multicolumn{3}{c|}{Q3/23} &
\multicolumn{3}{c|}{Q4/23} \\
\hline
\textdownarrow &
\textdownarrow &
\textdownarrow &
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} \\
\hline
\multicolumn{1}{|c|}{01/23} &
\multicolumn{1}{c|}{02/23} &
\multicolumn{1}{c|}{03/23} &
\multicolumn{3}{c|}{Q2/23} &
\multicolumn{3}{c|}{Q3/23} &
\multicolumn{3}{c|}{Q4/23} \\
\hline
&&& 
\textdownarrow &
\textdownarrow &
\textdownarrow &
\multicolumn{3}{c}{\textdownarrow} &
\multicolumn{3}{c}{\textdownarrow} \\
\cline{4-12}
&&&
\multicolumn{1}{|c|}{04/23} &
\multicolumn{1}{c|}{05/23} &
\multicolumn{1}{c|}{06/23} &
\multicolumn{3}{c|}{Q3/23} &
\multicolumn{3}{c|}{Q4/23} \\
\cline{4-12}
&&&&&& \vdots & \vdots & \vdots && \vdots &
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

顶部的页码显示使用了全文宽度。“神秘”-7\arrayrulewidth之处在于垂直行数最多为七行,位于第三行(不包括带箭头的行)。

答案3

{NiceTAbular}供参考,这是使用构建该表的一种方法nicematrix。您需要进行多次编译。

\documentclass[12pt]{book}
\usepackage{alltt}
\usepackage[a4paper, width = 160mm, top = 35mm, bottom = 30mm, 
            bindingoffset = 0mm]{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\centering
\newcommand{\One}{\Block[draw]{}}
\newcommand{\Three}{\Block[draw]{1-3}}
\newcommand{\Ar}{$\downarrow$}
\renewcommand{\arraystretch}{1.2}
    \begin{NiceTabular}{*{8}{X[c]}}
    \Block[draw]{1-*}{Cal-23} \\
    & \Ar &&& \Ar && \Ar & \Ar \\
    \Three{Q1/23} &&& \Three{Q2/23} &&& \One{Q3/23} & \One{Q4/23} \\
    \Ar & \Ar & \Ar & & \Ar & & \Ar & \Ar \\
    \One{Jan/23} & \One{Feb/23} & \One{Mar/23} & \Three{Q2/23} &&& \One{Q3/23} & \One{Q4/23} \\
    & & & \Ar & \Ar & \Ar & \Ar & \Ar \\
    \Block[borders={top,bottom}]{1-3}{} 
    &&& \One{Apr/23} & \One{May/23} & \One{Jun/23} & \One{Q3/23} & \One{Q4/23} 
    \end{NiceTabular}
\end{table}

\end{document}

上述代码的输出

相关内容