使用 arydshln 在表格中绘制虚线

使用 arydshln 在表格中绘制虚线

我正在尝试使用 arydshln 在表格中实现虚线。但是,该命令似乎无法正常工作,因为虚线不是从上到下绘制的,也就是说,在顶部看起来有点怪异。有人知道为什么这可能无法正常工作吗(或者是否可能与另一个包发生冲突?)。提前谢谢!

\documentclass[12pt]{article}
\usepackage[a4paper, left=2.5cm, right=2.5cm, top=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{csquotes}
%\usepackage{setspace}
%\onehalfspacing
\usepackage[style=apa]{biblatex}
\addbibresource{references.bib}
\usepackage{graphicx}
\graphicspath{ {figures/} }
\usepackage{array}
\usepackage{amsmath} 
\usepackage{amsfonts} 
\usepackage{amssymb}
\usepackage{comment}
\usepackage{booktabs}
\usepackage{afterpage}
\setlength{\parindent}{0em} 
\usepackage[hang]{footmisc}
\setlength{\footnotemargin}{-0.8em}
\usepackage{lscape}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage[labelfont=bf]{caption}
\usepackage[flushleft]{threeparttable}
\usepackage{hyperref} 
\renewcommand*{\nameyeardelim}{\addspace}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\usepackage{arydshln}

\begin{document}

\begin{landscape}
\begin{table}[p]\centering
\caption{Mean value of policies}
\begin{tabular}{lccc:cccc:cccccc}
\hline\hline
                    &         Mar20 &         Apr20&         Mai20&         Jun20&        Jul20&         Aug20&        Sep20&         Oct20&         Nov20&         Dec20&         Jan21&         Feb21\\
\hline\hline
C1 school              &          14&          26&          21&          13&          10&          10&           6&           4&           5&           6&           8&           5\\
C2 work                &           4&          13&           4&           0&           0&           0&           0&           1&           2&           1&           3&           2\\
C3 public events       &          14&          26&          25&          19&          16&          15&          15&          13&          14&          15&          16&          14\\
C4 gatherings          &           6&          16&          14&           7&           5&           6&           6&           7&           9&          11&          12&          12\\
C5 public transport    &           2&           7&           5&           3&           2&           1&           0&           0&           0&           0&           1&           1\\
C6 stay at home        &           5&          16&          12&           6&           4&           5&           5&           5&           7&           8&           9&           9\\
C7 internal movement   &           5&          16&          12&           5&           4&           4&           4&           3&           4&           5&           6&           4\\
\midrule
E1 income support      &           1&           3&           3&           4&           4&           4&           3&           4&           4&           4&           4&           3\\
E2 debt relief         &           3&          11&          14&          14&          14&          14&          14&          14&          12&          12&          11&          10\\
E3 fiscal stimulus     &         631&         933&         143&          33&          11&          28&          16&          37&           8&          81&           7&           6\\
\midrule
H1 info                &          22&          28&          30&          29&          29&          29&          28&          29&          28&          29&          29&          27\\
H2 testing             &           1&           3&           6&           8&           8&           8&           8&           8&           8&           8&           9&           9\\
H3 contact tracing     &          10&          13&          16&          18&          19&          20&          19&          19&          19&          19&          18&          16\\
H6 facial covering     &           0&           4&          10&          12&          14&          15&          17&          18&          19&          21&          21&          20\\
H7 vaccination         &           0&           0&           0&           0&           0&           0&           0&           0&           0&           1&           8&          10\\
\midrule
I1 government response &          31&          62&          61&          56&          53&          53&          52&          51&          52&          54&          55&          55\\
I2 stringency          &          41&          78&          72&          61&          56&          56&          53&          51&          53&          55&          58&          57\\
I3 containment / health&          33&          64&          62&          56&          53&          53&          52&          51&          53&          54&          57&          57\\
I4 economic support    &          13&          46&          52&          54&          54&          54&          54&          52&          50&          49&          46&          44\\
\hline\hline
\end{tabular}
\end{table}
\end{landscape}

\end{document}

答案1

arydshln这似乎是和之间的不兼容性\hline\hline

作为一种解决方法,我们可以使用{NiceTabular}它来nicematrix轻松绘制虚线规则,方法是使用垂直规则[tikz=dashed]说明符的选项|(版本≥6.24)。

使用 键first-row,第一行将不会绘制垂直线。

\documentclass[12pt]{article}
\usepackage[a4paper, left=2.5cm, right=2.5cm, top=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage{amsmath} 
\usepackage{amsfonts} 
\usepackage{amssymb}
\usepackage{booktabs}
\setlength{\parindent}{0em} 
\usepackage{lscape}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage[labelfont=bf]{caption}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

\begin{landscape}
\begin{table}[p]\centering
\caption{Mean value of policies}
\begin{NiceTabular}{lccc|[tikz=dashed]cccc|[tikz=dashed]ccccc}[first-row]
\hline\hline
                    &         Mar20 &         Apr20&         Mai20&         Jun20&        Jul20&         Aug20&        Sep20&         Oct20&         Nov20&         Dec20&         Jan21&         Feb21\\
\hline\hline
C1 school              &          14&          26&          21&          13&          10&          10&           6&           4&           5&           6&           8&           5\\
C2 work                &           4&          13&           4&           0&           0&           0&           0&           1&           2&           1&           3&           2\\
C3 public events       &          14&          26&          25&          19&          16&          15&          15&          13&          14&          15&          16&          14\\
C4 gatherings          &           6&          16&          14&           7&           5&           6&           6&           7&           9&          11&          12&          12\\
C5 public transport    &           2&           7&           5&           3&           2&           1&           0&           0&           0&           0&           1&           1\\
C6 stay at home        &           5&          16&          12&           6&           4&           5&           5&           5&           7&           8&           9&           9\\
C7 internal movement   &           5&          16&          12&           5&           4&           4&           4&           3&           4&           5&           6&           4\\
\midrule
E1 income support      &           1&           3&           3&           4&           4&           4&           3&           4&           4&           4&           4&           3\\
E2 debt relief         &           3&          11&          14&          14&          14&          14&          14&          14&          12&          12&          11&          10\\
E3 fiscal stimulus     &         631&         933&         143&          33&          11&          28&          16&          37&           8&          81&           7&           6\\
\midrule
H1 info                &          22&          28&          30&          29&          29&          29&          28&          29&          28&          29&          29&          27\\
H2 testing             &           1&           3&           6&           8&           8&           8&           8&           8&           8&           8&           9&           9\\
H3 contact tracing     &          10&          13&          16&          18&          19&          20&          19&          19&          19&          19&          18&          16\\
H6 facial covering     &           0&           4&          10&          12&          14&          15&          17&          18&          19&          21&          21&          20\\
H7 vaccination         &           0&           0&           0&           0&           0&           0&           0&           0&           0&           1&           8&          10\\
\midrule
I1 government response &          31&          62&          61&          56&          53&          53&          52&          51&          52&          54&          55&          55\\
I2 stringency          &          41&          78&          72&          61&          56&          56&          53&          51&          53&          55&          58&          57\\
I3 containment / health&          33&          64&          62&          56&          53&          53&          52&          51&          53&          54&          57&          57\\
I4 economic support    &          13&          46&          52&          54&          54&          54&          54&          52&          50&          49&          46&          44\\
\hline\hline
\end{NiceTabular}
\end{table}
\end{landscape}

\end{document}

上述代码的输出

也可以;用标准命令定义新的列类型\newcolumntype(为了易读):

\newcolumntype{;}{|[tikz=dashed]}

答案2

  • 不太清楚,你的问题是什么?第一个表格行中没有垂直虚线,而第二个表格行中的垂直虚线不完整?

  • 不过,我想知道为什么您使用混合booktabs规则和双\hlines。

  • \hline如果使用两个 s的话\toprule,印刷效果会更好(和更专业)\bottomrule

  • 您可以考虑使用tabularray包来编写表格。通过使用它,表格的代码更加一致,并且从表格的顶部到底部绘制虚线:

\documentclass[12pt]{article}
\usepackage[a4paper, margin=2.5cm]{geometry}

% no arydshln package, it is not needed for this table
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\setlength{\parindent}{0em}

\usepackage{pdflscape}
\usepackage[labelfont=bf]{caption}

\begin{document}
\begin{landscape}
    \begin{table}[p]
    \centering
\caption{Mean value of policies}
    \sisetup{table-format=2.0}
\begin{tblr}{vline{2,5,9}={dashed},
             colspec = {@{}
                        l *{3}{X[c, si={table-format=3.0}]}
                          *{4}{X[c, si]}
                          *{5}{X[c, si]}
                        @{}},
             row{1}  = guard
             }
    \toprule
                    &    Mar20  &    Apr20  &    Mai20  &    Jun20  &    Jul20  &    Aug20  &    Sep20  &    Oct20
                    &    Nov20  &    Dec20  &    Jan21  &    Feb21              \\
    \midrule
C1 school           &   14      &   26      &   21      &   13      &   10      &   10      &   6       &   4
                    &   5       &   6       &   8       &   5                   \\
C2 work             &   4       &   13      &   4       &   0       &   0       &   0       &   0       &   1
                    &   2       &   1       &   3       &   2                   \\
C3 public events    &   14      &   26      &   25      &   19      &   16      &   15      &   15      &   13
                    &   14      &   15      &   16      &   14                  \\
C4 gatherings       &   6       &   16      &   14      &   7       &   5       &   6       &   6       &   7
                    &   9       &   11      &   12      &   12                  \\
C5 public transport &   2       &   7       &   5       &   3       &   2       &   1       &   0       &   0
                    &   0       &   0       &   1       &   1                   \\
C6 stay at home     &   5       &   16      &   12      &   6       &   4       &   5       &   5       &   5
                    &   7       &   8       &   9       &   9                   \\
C7 internal movement    &   5   &   16      &   12      &   5       &   4       &   4       &   4       &   3
                    &   4       &   5       &   6       &   4                   \\
    \midrule
E1 income support   &   1       &   3       &   3       &   4       &   4       &   4       &   3       &   4
                    &   4       &   4       &   4       &   3                   \\
E2 debt relief      &   3       &   11      &   14      &   14      &   14      &   14      &   14      &   14
                    &   12      &   12      &   11      &   10                  \\
E3 fiscal stimulus  &   631     &   933     &   143     &   33      &   11      &   28      &   16      &   37
                    &           8   &   81  &   7       &   6                   \\
    \midrule
H1 info             &   22      &   28      &   30      &   29      &   29      &   29      &   28      &   29
                    &   28      &   29      &   29      &   27                  \\
H2 testing          &   1       &   3       &   6       &   8       &   8       &   8       &   8       &   8
                    &   8       &   8       &   9       &   9                   \\
H3 contact tracing  &   10      &   13      &   16      &   18      &   19      &   20      &   19      &   19
                    &   19      &   19      &   18      &   16                  \\
H6 facial covering  &   0       &   4       &   10      &   12      &   14      &   15      &   17      &   18
                    &   19      &   21      &   21      &   20                  \\
H7 vaccination      &   0       &   0       &   0       &   0       &   0       &   0       &   0       &   0
                    &   0       &   1       &   8       &   10                  \\
    \midrule
I1 government response  &   31  &   62      &   61      &   56      &   53      &   53      &   52      &   51
                    &   52      &   54      &   55      &   55                  \\
I2 stringency       &   41      &   78      &   72      &   61      &   56      &   56      &   53      &   51
                    &   53      &   55      &   58      &   57                  \\
I3 containment / health &   33  &   64      &   62      &   56      &   53      &   53      &   52      &   51
                    &   53      &   54      &   57      &   57                  \\
I4 economic support &   13      &   46      &   52      &   54      &   54      &   54      &   54      &   52
                    &   50      &   49      &   46      &   44                  \\
    \bottomrule
\end{tblr}
    \end{table}
\end{landscape}
\end{document}

在此处输入图片描述

表格左上角的详细信息:

在此处输入图片描述

  • 如果由于某些(未知的)原因你坚持在表中使用双行,那么使用tabularraypackae 很容易获得:
\documentclass[12pt]{article}
\usepackage[a4paper, margin=2.5cm]{geometry}

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

\setlength{\parindent}{0em}

\usepackage{pdflscape}
\usepackage[labelfont=bf]{caption}


\begin{document}
\begin{landscape}
    \begin{table}[p]
    \centering
\caption{Mean value of policies}
    \sisetup{table-format=2.0}
\begin{tblr}{hline{1,2,Z} = {1}{-}{},
             hline{1,2,Z} = {2}{-}{},
             vline{2,5,9}={dashed},
             colspec = {@{}
                        l *{3}{X[c, si={table-format=3.0}]}
                          *{4}{X[c, si]}
                          *{5}{X[c, si]}
                        @{}},
             row{1}  = guard
             }
                    &    Mar20  &    Apr20  &    Mai20  &    Jun20  &    Jul20  &    Aug20  &    Sep20  &    Oct20
                    &    Nov20  &    Dec20  &    Jan21  &    Feb21              \\
C1 school           &   14      &   26      &   21      &   13      &   10      &   10      &   6       &   4
                    &   5       &   6       &   8       &   5                   \\
C2 work             &   4       &   13      &   4       &   0       &   0       &   0       &   0       &   1
                    &   2       &   1       &   3       &   2                   \\
C3 public events    &   14      &   26      &   25      &   19      &   16      &   15      &   15      &   13
                    &   14      &   15      &   16      &   14                  \\
C4 gatherings       &   6       &   16      &   14      &   7       &   5       &   6       &   6       &   7
                    &   9       &   11      &   12      &   12                  \\
C5 public transport &   2       &   7       &   5       &   3       &   2       &   1       &   0       &   0
                    &   0       &   0       &   1       &   1                   \\
C6 stay at home     &   5       &   16      &   12      &   6       &   4       &   5       &   5       &   5
                    &   7       &   8       &   9       &   9                   \\
C7 internal movement    &   5   &   16      &   12      &   5       &   4       &   4       &   4       &   3
                    &   4       &   5       &   6       &   4                   \\
    \midrule
E1 income support   &   1       &   3       &   3       &   4       &   4       &   4       &   3       &   4
                    &   4       &   4       &   4       &   3                   \\
E2 debt relief      &   3       &   11      &   14      &   14      &   14      &   14      &   14      &   14
                    &   12      &   12      &   11      &   10                  \\
E3 fiscal stimulus  &   631     &   933     &   143     &   33      &   11      &   28      &   16      &   37
                    &           8   &   81  &   7       &   6                   \\
    \midrule
H1 info             &   22      &   28      &   30      &   29      &   29      &   29      &   28      &   29
                    &   28      &   29      &   29      &   27                  \\
H2 testing          &   1       &   3       &   6       &   8       &   8       &   8       &   8       &   8
                    &   8       &   8       &   9       &   9                   \\
H3 contact tracing  &   10      &   13      &   16      &   18      &   19      &   20      &   19      &   19
                    &   19      &   19      &   18      &   16                  \\
H6 facial covering  &   0       &   4       &   10      &   12      &   14      &   15      &   17      &   18
                    &   19      &   21      &   21      &   20                  \\
H7 vaccination      &   0       &   0       &   0       &   0       &   0       &   0       &   0       &   0
                    &   0       &   1       &   8       &   10                  \\
    \midrule
I1 government response  &   31  &   62      &   61      &   56      &   53      &   53      &   52      &   51
                    &   52      &   54      &   55      &   55                  \\
I2 stringency       &   41      &   78      &   72      &   61      &   56      &   56      &   53      &   51
                    &   53      &   55      &   58      &   57                  \\
I3 containment / health &   33  &   64      &   62      &   56      &   53      &   53      &   52      &   51
                    &   53      &   54      &   57      &   57                  \\
I4 economic support &   13      &   46      &   52      &   54      &   54      &   54      &   54      &   52
                    &   50      &   49      &   46      &   44                  \\
\end{tblr}
    \end{table}
\end{landscape}
\end{document}

在此处输入图片描述

相关内容