与 fbox 失去对齐

与 fbox 失去对齐

我正在使用这个命令将东西放在一个盒子里。

\newcommand{\cfbox}[1]{%
{\color{black}%
\setlength\fboxsep{0pt}\fbox{
    \begin{varwidth}{\dimexpr\columnwidth-2}
      \leavevmode{\color{black}#1}
    \end{varwidth}
  }
}%
}

在此处输入图片描述

问题是每个块都有不同的对齐方式,我希望所有块都与第一个块对齐。

另外,这不是问题的核心,但如果有人知道的话:如何将表格标题重新居中?使用该命令后,文本移到了左边...(虽然没有必要回答这个问题)。

以下是要运行的示例

\documentclass{acmart}
\usepackage[utf8]{inputenc}
\usepackage{varwidth}
\usepackage{tikz}

\newcommand{\cfbox}[1]{%
{\setlength\fboxsep{0pt}\fbox{
   \begin{varwidth}{\dimexpr\columnwidth-2}
       \leavevmode{\color{black}#1}
   \end{varwidth}%
   }
}
}

\begin{document}

\cfbox{
\cfbox{
\section{Introduction}
}
\cfbox{
If you are new to publishing with ACM, this document is a valuable
guide to the process of preparing your work for publication. If you
have published with ACM before, this document provides insight and
instruction into more recent changes to the article template.
}
}

\cfbox{
\begin{table}[H]   
\caption{Frequency of Special Characters}  
\label{tab:freq}
\cfbox{
    \begin{tabular}{ccl}
        \toprule
        Non-English or Math&Frequency&Comments\\
        \midrule
        \O & 1 in 1,000& For Swedish names\\
        $\pi$ & 1 in 5& Common in math\\
        \$ & 4 in 5 & Used in business\\
        $\Psi^2_1$ & 1 in 40,000& Unexplained usage\\
    \bottomrule
    \end{tabular}
}
\end{table}
}

\cfbox{
\begin{table}[H]   
\caption{Frequency of Special Characters}  
\label{tab:freq}
\cfbox{
    \begin{tabular}{ccl}
        \toprule
        Non-English or Math&Frequency&Comments\\
        \midrule
        \O & 1 in 1,000& For Swedish names\\
        $\pi$ & 1 in 5& Common in math\\
        \$ & 4 in 5 & Used in business\\
        $\Psi^2_1$ & 1 in 40,000& Unexplained usage\\
        \bottomrule
    \end{tabular}
}
\end{table}
}

\end{document}

答案1

我找到了答案,tex 上的 maketitle 会影响某些特定 cfbox 的对齐方式。如果有 maketitle,则表格和部分的 cfbox 之间不应有空行,否则对齐方式会发生变化。另一方面,如果 tex 上没有 maketitle,则需要在表格和部分的 cfbox 之间留一个空行,否则对齐方式会向相反方向变化。评论说我应该在 cfbox 上放置 %,但在 tex 上的所有地方都放置 % 后,没有任何变化。

我仍然不知道如何将表格描述居中。下面的文本显示了使用 maketitle 时示例按预期运行的情况。

\documentclass[acmsmall, natbib=false, review]{acmart}

\usepackage{varwidth}

\copyrightyear{2018}
\acmYear{2018}
\acmDOI{10.1145/1122445.1122456}
\acmConference[Woodstock '18]{Woodstock '18: ACM 
Symposium 
on Neural
Gaze Detection}{June 03--05, 2018}{Woodstock, NY}
\acmBooktitle{Woodstock '18: ACM Symposium on Neural 
Gaze 
Detection,
June 03--05, 2018, Woodstock, NY}
\acmPrice{15.00}
\acmISBN{978-1-4503-XXXX-X/18/06}

\newcommand{\cfbox}[1]{%
{\setlength\fboxsep{0pt}\fbox{%
    \begin{varwidth}{\dimexpr\columnwidth}%
        {\leavevmode\color{black}#1}%
    \end{varwidth}%
    }% 
}
}

\begin{document}

\title{Test}

\maketitle



\cfbox{

\cfbox{
\section{Introduction}
}

\cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

\cfbox{
\begin{table}[H]   
\caption{Frequency of Special Characters}  
\label{tab:freq}
\cfbox{
\begin{tabular}{ccl}
\toprule
Non-English or Math&Frequency&Comments\\
\midrule
\O & 1 in 1,000& For Swedish names\\
$\pi$ & 1 in 5& Common in math\\
\$ & 4 in 5 & Used in business\\
$\Psi^2_1$ & 1 in 40,000& Unexplained usage\\
\bottomrule
\end{tabular}
}
\end{table}
}
\cfbox{
\cfbox{
\section{Introduction}
}

\cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article  
template.
}

}

\cfbox{

\cfbox{
\section{Introduction}
}

\cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

\cfbox{

\cfbox{
\section{Introduction}
}

\cfbox{
If you are new to publishing with ACM, this document is 
a 
valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

\cfbox{

\cfbox{
\section{Introduction}
}

\cfbox{
If you are new to publishing with ACM, this document is 
a 
valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article             
template.
}

}


\end{document}
\endinput

相关内容