因此,我必须承认我已经摆脱了深度,不知道自己在做什么。
对于这个冗长而复杂的问题,我提前表示歉意。
我正在尝试建立此输出:
我已经成功(某种程度上)完成了。
然而,我真正想要做的是创建一个新的环境来offset
自动执行此操作,并将文本占用的行数作为参数。
我已经将代码放在了里面以创建环境
\newenvironment{offset}
{
Code before content
}
{
Code after content
}
但当我尝试使用时,begin{offset} . . . \end{offset}
我得到了偏移环境的基本框架和 tikz 线条,但没有文本。我做错了什么(好吧,有多少)?
这是我编写的代码,带有注释块,以便更轻松地测试环境调用内部和外部的绘图和放置代码。
\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}
\newenvironment{offset}
{
\begin{wrapfigure}[19]{r}[1in]{2in}
\noindent
\newlength{\topverticalspacer}
\setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
\vspace*{\topverticalspacer}\\
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\node (0, 0) (n1) {};
\draw[-,line width=1pt] (n1)--(2in, 0);
\end{tikzpicture}\\
\newlength{\verticalspacer}
\setlength{\verticalspacer}{\tabcolsep-\baselineskip}
\vspace*{\verticalspacer}\\
\hspace*{\tabcolsep}
\parbox{1.75in}{\textsf{
\hspace{-5pt}
}
{
}}
\newlength{\bottomspacer}
\setlength{\bottomspacer}{\baselineskip-\tabcolsep}
\vspace*{\bottomspacer}\\
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\node (0, 0) (n2) {};
\draw[-,line width=1pt] (n2)--(1in, 0);
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\draw[-,line width=1pt] (n1) -- (n2);
\end{tikzpicture}
\end{wrapfigure}
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{offset}
% \begin{wrapfigure}[19]{r}[1in]{2in}
% \noindent
% \newlength{\topverticalspacer}
% \setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
% \vspace*{\topverticalspacer}\\
% \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
% \node (0, 0) (n1) {};
% \draw[-,line width=1pt] (n1)--(2in, 0);
% \end{tikzpicture}\\
% \newlength{\verticalspacer}
% \setlength{\verticalspacer}{\tabcolsep-\baselineskip}
% \vspace*{\verticalspacer}\\
% \hspace*{\tabcolsep}
% \parbox{1.75in}{\textsf{
% \hspace{-5pt}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
% }}
% \newlength{\bottomspacer}
% \setlength{\bottomspacer}{\baselineskip-\tabcolsep}
% \vspace*{\bottomspacer}\\
% \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
% \node (0, 0) (n2) {};
% \draw[-,line width=1pt] (n2)--(1in, 0);
% \end{tikzpicture}
% \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
% \draw[-,line width=1pt] (n1) -- (n2);
% \end{tikzpicture}
% \end{wrapfigure}
\end{offset}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\lipsum[2-4]
\end{document}
抱歉,MWE 太长了,而且使用了原始的 lorem ipsum,我不希望 Lipsum 插入段落分隔符。
答案1
你遗漏了很多%
行末的
\parbox{1.75in}{\textsf{
\hspace{-5pt}
}
{
}}
总是会生成一个空的 parbox。
我不认为 tikz 代码在这里真的有帮助,如果你只想画三条线,它只会让事情变得复杂。
\documentclass[final,oneside,11pt]{memoir}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}
\newenvironment{offset}
{%
\wrapfigure{r}[1in]{2in}%
\kern-5pt
\hrule
\noindent\hbox\bgroup\vrule \kern9.6pt\minipage{\dimexpr2in-10pt\relax}%
\kern5pt
}
{%
\par
\kern5pt
\endminipage\egroup
\hrule width 1in
\endwrapfigure
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{offset}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{offset}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\lipsum[2-4]
\end{document}
答案2
有几件事对你不起作用。首先,你定义的新长度应该在环境之外定义。其次,你不能\parbox{1.75in}{
在新环境中调用定义的一部分,然后在第二部分中关闭它。最好使用 来lrbox
实现此目的。第三,wrapfigure
需要直接从你定义的新环境中调用 ,而不是使用begin{wrapfigure}
。此外,你只需要一个tikzpicture
就可以完成你想要的。
\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}
%% this is where you should define your new lengths
% \newlength{\topverticalspacer}
% \newlength{\verticalspacer}
% \newlength{\bottomspacer}
\newsavebox\myoffsetbox
\newenvironment{offset}
{%%
\begin{lrbox}{\myoffsetbox}
\begin{minipage}[t]{1.75in}
\sffamily
\noindent
\hspace{-5pt}%%
}
{%%
\end{minipage}
\end{lrbox}%%
\wrapfigure[19]{r}[1in]{2in}
\raisebox{\dimexpr\ht\myoffsetbox+\tabcolsep}[0pt][0pt]{\tikzmark{aen1}}%%
\hspace*{\tabcolsep}%%
\usebox{\myoffsetbox}%%
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\draw[line width=1pt]
($({pic cs:aen1})+(2in,0)$) --
(pic cs:aen1) --
++ (0,-\dimexpr\ht\myoffsetbox+\dp\myoffsetbox+2\tabcolsep) --
++ (1in,0);
\end{tikzpicture}\\
\endwrapfigure%%
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{offset}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{offset}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\lipsum[2-4]
\end{document}
通过使用lrbox
,您可以测量偏移段落的宽度、高度和深度,以更好地适应框架。
更新
各种环境都没有玩的不错在 a 内\newenvironment
:这通常是因为此类环境如何通过搜索各自的 来提前扫描以查找其内容\end{<environment name>
。这似乎就是这里的情况\begin{wrapfigure}
。
通过使用lrbox
,我可以测量要偏移的文本内容。最初,我使用\tikzmark
在页面上创建一个标记来引用此偏移材料的开头。我曾经 根据其高度( )和 的值\raisebox
将其提升\tikzmark
到偏移材料顶部的高度之上。我不希望向页面添加任何视觉空白,因此我向它传递了两个可选参数(我可能不需要两者):第一个可选参数表示将\ht\myoffsetbox
\tabcolsep
\raisebox
凸起的盒子高度为0pt
,第二个可选参数表示分配凸起的盒子深度0pt
。
使用\tikzmark
自己的坐标系统。\tikzmark{<node name>}
正确 地,我需要写pic cs:<node name>
。calc
({pic cs:aen1})
(<node name 1>-|<node name 2>)
({pic cs:aen1}-|{pic cs:aen2})
答案3
另一种选择是使用newcommand
类似于的newenvironment
。
代码
\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}
\newcommand*{\offset}[1]
{
\begin{wrapfigure}[19]{r}[1in]{2in}
\noindent
\newlength{\topverticalspacer}
\setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
\vspace*{\topverticalspacer}\\
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\coordinate (n1) at (0, 0);
\draw[-,line width=1pt,inner sep=0pt,outer sep=0pt] (n1)--(2in, 0);
\end{tikzpicture}\\
\newlength{\verticalspacer}
\setlength{\verticalspacer}{\tabcolsep-\baselineskip}
\vspace*{\verticalspacer}\\
\hspace*{\tabcolsep}
%}
%{
\parbox{1.75in}{\textsf{
\hspace{-5pt}
#1}}
\newlength{\bottomspacer}
\setlength{\bottomspacer}{\baselineskip-\tabcolsep}
\vspace*{\bottomspacer}\\
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt,outer sep=0pt]
\coordinate (n2) at (0, 0);
\draw[-,line width=1pt] (n2)--(1in, 0);
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
\draw[-,line width=1pt] (n1) -- (n2);
\end{tikzpicture}
\end{wrapfigure}
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\offset{%
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
}
Lorem ipsum dolor sit amet, consectetur adipisicing 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. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\lipsum[2-4]
\end{document}