tikzpicture 环境使得 \noindent 无效

tikzpicture 环境使得 \noindent 无效

请参阅此 MWE:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[showframe]{geometry}
\usepackage{ulem}
\setlength\fboxsep{0pt}
\begin{document}

% \begin{tikzpicture}[remember picture, overlay]
%   \node[inner sep=0pt] at (current page.center) {\includegraphics[width=\textwidth]{example-image.pdf}};
% \end{tikzpicture}
\ExplSyntaxOn
\noindent
\fbox{\begin{minipage}{\textwidth}
  \mode_leave_vertical:
  \hbox_to_wd:nn { 2cm } { Classification }
  \uline { \hbox_to_wd:nn { 2.4cm } { \hfill 1234 \hfill } }
  \hfill
  \hbox_to_wd:nn { 1.67cm } { Secret-level }
  \uline { \hbox_to_wd:nn { 2.4cm } { \hfill AAAA \hfill } }
\end{minipage}}
\ExplSyntaxOff

\noindent\begin{minipage}{\textwidth}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
\end{minipage}

\end{document}

如果我取消注释该tikzpicture部分,则第一个小页面会缩进,即使\noindent在其之前还有。 在此处输入图片描述

答案1

开始tikzpicture一个段落,因此\noindent没有效果。

将其移到之前\begin{tikzpicture}(我添加了\ignorespaces以避免在之前出现不必要的空格minipage,但您也可以使用注释字符%)。

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[showframe]{geometry}
\usepackage{ulem}
\setlength\fboxsep{0pt}
\begin{document}

\noindent
\begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0pt] at (current page.center) {\includegraphics[width=\textwidth]{example-image.pdf}};
\end{tikzpicture}\ignorespaces
\ExplSyntaxOn
\fbox{\begin{minipage}{\textwidth}
  \mode_leave_vertical:
  \hbox_to_wd:nn { 2cm } { Classification }
  \uline { \hbox_to_wd:nn { 2.4cm } { \hfill 1234 \hfill } }
  \hfill
  \hbox_to_wd:nn { 1.67cm } { Secret-level }
  \uline { \hbox_to_wd:nn { 2.4cm } { \hfill AAAA \hfill } }
\end{minipage}}
\ExplSyntaxOff

\noindent\begin{minipage}{\textwidth}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
\end{minipage}

\end{document}

例子

答案2

我不确定expl3在这种情况下使用会给你带来多少好处。更直接地说,你只是把事情复杂化了,因为 LaTeX 已经有了所需的工具。

minipage嵌套的顶部\fbox应为\framebox。还要注意端线。

\documentclass[a4paper]{article}
\usepackage{tikz}
%\usepackage[showframe]{geometry}
\usepackage{ulem}

\begin{document}

\noindent
\begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0pt] at (current page.center) {%
    \includegraphics[width=\textwidth]{example-image.pdf}%
  };
\end{tikzpicture}% <--- important
\begingroup\setlength{\fboxsep}{0pt}%
\framebox[\dimeval{\textwidth-2\fboxrule}][s]{%
  \strut
  \,Classification
  \uline{\makebox[2.4cm][c]{1234}}%
  \hfill
  Secret-level
  \uline{\makebox[2.4cm][c]{AAAA}}%
}
\endgroup

\bigskip

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur.

\end{document}

的宽度\framebox已通过 进行校正\fboxrule,因此不会过满。

应该\noindent在 之前tikzpicture

\documentclass[a4paper]{article}
\usepackage{tikz}
%\usepackage[showframe]{geometry}
\usepackage{ulem}

\begin{document}

\noindent
\begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0pt] at (current page.center) {%
    \includegraphics[width=\textwidth]{example-image.pdf}%
  };
\end{tikzpicture}% <--- important
\begingroup\setlength{\fboxsep}{0pt}%
\framebox[\dimeval{\textwidth-2\fboxrule}][s]{%
  \strut
  \,Classification
  \uline{\makebox[2.4cm][c]{1234}}%
  \hfill
  Secret-level
  \uline{\makebox[2.4cm][c]{AAAA}}%
}
\endgroup

\bigskip

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur.

\end{document}

在此处输入图片描述

相关内容