我正在尝试使用定义的边距几何学加载以使用绘制几个花哨的部分标题蒂克兹。为了制作\Gm@lmargin
和\Gm@rmargin
使用,我必须做
\makeatletter\Gm@lmargin
\makeatletter\Gm@rmargin
我只能在之后这样做\begin{document}
。由于我之前定义了许多标题和其他内容,因此我想在加载 geomtry 包或\newgeometry
定义之后立即使这些边距可用。
你知道\makeatletter\Gm@lmargin
之前该怎么做\begin{document}
吗?
梅威瑟:
\documentclass[a4paper]{report}
\usepackage[left=3.5cm, right=1.5cm, top=2.5cm, bottom=2.5cm]{geometry}
%I'd like to make them usable here
\usepackage{tikz,bm}
\usetikzlibrary{arrows}
\usetikzlibrary{calc,positioning}
%Definition of fancy stuff
\begin{document}
%I get errors if done before this point
\makeatletter\Gm@lmargin
\makeatletter\Gm@rmargin
\vspace{2cm}
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=east,xshift=-\Gm@rmargin,rectangle,draw=black,fill=white] at (current page.east|-0,0) {Section};
\end{tikzpicture}
\end{document}
我已经尝试过@Heiko Oberdiek和@Werner,这是 MWE:
\documentclass[a4paper]{report}
\newdimen\plmargin \setlength{\plmargin}{3.5cm}
\newdimen\prmargin \setlength{\prmargin}{1.5cm}
\usepackage[left=\plmargin, right=\prmargin, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{tikz,bm}
\usetikzlibrary{arrows,calc,positioning}
\newdimen\mylmargin \setlength{\mylmargin}{\dimexpr\oddsidemargin+1in\relax}
\newdimen\myrmargin \setlength{\myrmargin}{\dimexpr\paperwidth-\oddsidemargin-1in-\textwidth\relax}
\makeatletter
\newdimen\Gmrmargin \setlength{\Gmrmargin}{\dimexpr\Gm@rmargin}
\newdimen\Gmlmargin \setlength{\Gmlmargin}{\dimexpr\Gm@lmargin}
\makeatother
\begin{document}
\noindent
plmargin: \the\plmargin ~prmargin: \the\prmargin \\
oddsidemargin: \the\oddsidemargin ~evensidemargin: \the\evensidemargin \\
mylmargin: \the\mylmargin ~myrmagin: \the\myrmargin \\
Gmlmargin: \the\Gmlmargin ~Gmrmargin: \the\Gmrmargin
\end{document}
结果如下:
plmargin: 99.58464pt prmargin: 42.67912pt
oddsidemargin: 27.31465pt evensidemargin: 27.31465pt
mylmargin: 99.58464pt myrmagin: 42.67912pt
Gmlmargin: 99.58464pt Gmrmargin: 42.67912pt
两者都很好用。解决方案由@Werner取决于几何定义的变量,正如我所问的。然而,@Heiko Oberdiek指出为什么最好使用官方长度寄存器:
\Gm@lmargin 和 \Gm@rmargin 并非总是定义。如果不使用包 geometry,则它们是未知的。如果使用包 geometry,则取决于选项;例如,\usepackage[pass]{geometry} 将不会定义它们。
答案1
\Gm@lmargin
和\Gm@rmargin
是属于实现细节的内部宏,在包的任何后续版本中可能会发生变化geometry
。
相反,我将使用两个 dimen 寄存器来代替内部寄存器:
\documentclass[a4paper]{report}
\newdimen\myleftmargin
\newdimen\myrightmargin
\setlength{\myleftmargin}{3.5cm}
\setlength{\myrightmargin}{1.5cm}
\usepackage[
left=\myleftmargin,
right=\myrightmargin,
top=2.5cm,
bottom=2.5cm
]{geometry}
\usepackage{tikz,bm}
\usetikzlibrary{arrows}
\usetikzlibrary{calc,positioning}
% Definition of fancy stuff
% \myleftmargin and \myrightmargin can be used here
\begin{document}
left margin: \the\myleftmargin, right margin: \the\myrightmargin
\vspace{2cm}
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=east,xshift=-\myrightmargin,rectangle,draw=black,fill=white]
at (current page.east|-0,0) {Section};
\end{tikzpicture}
\end{document}