请参阅此 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}
答案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}