在搜索过程中,我发现了一些在线图片,虽然我怀疑它们不是用 Latex 制作的 - 但是,我发现它们对于理解正在发生的事情非常有用。
我很确定下面的图像不是由 latex 自动生成的 - 所以我想知道是否有一个 latex 包(或方法) - 可以用箭头可视化所需的长度(甚至可能是长度值?),如下图所示(显然,从网络添加它们会在 imgur 上添加一份副本;我也添加了原始链接)。
在以下情况下,它们与列表(枚举/逐项列出)参数相关 - 但我对可视化\parindent
或\parskip
段落上下文也很感兴趣。
有没有什么可以实现类似的可视化(可能也可以基于“每页请求”进行工作;不想让 100 pg 的 .pdf 在每个段落上都充满箭头矢量:)
)
答案1
显示长度的一个默认包是包layouts
. 它可生成具有表示长度的黑白图像。
例如下面的示例为列表环境生成了以下图像。
\documentclass{article}
\usepackage{layouts}
\begin{document}
\listdiagram
\end{document}
然而彩色图像可能是由 TikZ 或 PSTricks 等包制作的。
答案2
好吧,我只是想在这里发布这个片段 - 不太像layouts
,这个片段创建了一个命令\showpagemarginstwh
,它只显示页边距(基于\textwidth
和\textheight
)使用LaTeX \放入命令:
\newlength{\tmvx}
\newlength{\tmvy}
\newlength{\curposy}
\newcommand{\showpagemarginstwh}{%
\setlength{\curposy}{\dimexpr\pagetotal+\baselineskip}
%\typeout{\the\curposy}
\edef\mw{\getlength{\textwidth}}
\edef\mh{\getlength{\textheight}}
\edef\mp{\getlength{\parindent}}
\setlength{\tmvx}{\textwidth}
%\addtolength{\tmvx}{-\parindent} % use offset
\setlength{\tmvy}{0.45\textheight}
\edef\mvx{\getlength{\tmvx}}
\edef\mvy{\getlength{\curposy}}
%\begin{picture}(width,height)(x-offset,y-offset)
\begin{picture}(0,0)(\mp,-\mvy)
\put(0,0) {\line(1,0){\mw}}
\put(0,0) {\line(0,-1){\mh}}
\put(\mvx,0) {\line(0,-1){\mh}}
\put(0,-\mh) {\line(1,0){\mw}}
\end{picture}
}
下面是一个 MWE,它生成以下两页输出:
\documentclass{article}
% reminder: US letter: 596pt x 795pt
% https://tex.stackexchange.com/a/55852/2595
\newlength{\pagewidthA}\newlength{\pageheightA}
\setlength{\pagewidthA}{300bp}\setlength{\pageheightA}{400bp}
\newlength{\pagewidthB}\newlength{\pageheightB}
\setlength{\pagewidthB}{400bp}\setlength{\pageheightB}{500bp}
\usepackage{geometry}
\newcommand{\generatePageLayouts}{%
\newgeometry{layoutwidth=\pagewidthA,layoutheight=\pageheightA,left=5mm,right=1mm,bottom=12mm,top=1mm}
\savegeometry{LayoutPageA}
\newgeometry{layoutwidth=\pagewidthB,layoutheight=\pageheightB,twoside,inner=2.5cm,outer=0.5cm,top=1.5cm,bottom=1.5cm}
\savegeometry{LayoutPageB}
}
\newcommand{\switchToLayoutPageA}{%
% doesn't include page sizes; so page size too:
\pdfpagewidth=\pagewidthA \pdfpageheight=\pageheightA % for PDF output
\paperwidth=\pagewidthA \paperheight=\pageheightA % for TikZ
\loadgeometry{LayoutPageA} % note; \loadgeometry may reset paperwidth/h!
\paperwidth=\pagewidthA \paperheight=\pageheightA % for TikZ
}
\newcommand{\switchToLayoutPageB}{%
% doesn't include page sizes; so page size too:
\pdfpagewidth=\pagewidthB \pdfpageheight=\pageheightB % for PDF output
\paperwidth=\pagewidthB \paperheight=\pageheightB % for TikZ
\loadgeometry{LayoutPageB} % note; \loadgeometry may reset paperwidth/h!
\paperwidth=\pagewidthB \paperheight=\pageheightB % for TikZ
}
\usepackage{lipsum}
% https://tex.stackexchange.com/a/15002/2595
% to extract numbers from lengths:
% NOTE: \getlength gets numeric portion as pt always;
\makeatletter
\newcommand*{\getlength}[1]{\strip@pt#1}
\makeatother
% https://tex.stackexchange.com/a/56058/2595
% https://tex.stackexchange.com/a/17813/2595
% http://www.latex-community.org/forum/viewtopic.php?f=9&t=13098
%
% display page margins based on \textwidth/height
% note \begin{picture} is treated like character;
% so we "lift" it from current position in page
% to make it align to margins
\newlength{\tmvx}
\newlength{\tmvy}
\newlength{\curposy}
\newcommand{\showpagemarginstwh}{%
\setlength{\curposy}{\dimexpr\pagetotal+\baselineskip}
%\typeout{\the\curposy}
\edef\mw{\getlength{\textwidth}}
\edef\mh{\getlength{\textheight}}
\edef\mp{\getlength{\parindent}}
\setlength{\tmvx}{\textwidth}
%\addtolength{\tmvx}{-\parindent} % use offset
\setlength{\tmvy}{0.45\textheight}
\edef\mvx{\getlength{\tmvx}}
\edef\mvy{\getlength{\curposy}}
%\begin{picture}(width,height)(x-offset,y-offset)
\begin{picture}(0,0)(\mp,-\mvy)
\put(0,0) {\line(1,0){\mw}}
\put(0,0) {\line(0,-1){\mh}}
\put(\mvx,0) {\line(0,-1){\mh}}
\put(0,-\mh) {\line(1,0){\mw}}
\end{picture}
}
\begin{document}
% here geometry layout L1 is instantiated;
% generate page layouts first based on layoutwidth as page size;
% don't switch actual page sizes yet:
\generatePageLayouts{}
%%% start with content
% start with LayoutPageA (includes switching page size)
\switchToLayoutPageA{}
\lipsum[1]
\showpagemarginstwh
\lipsum[2]
\clearpage
\switchToLayoutPageB{}
\lipsum[3]
\showpagemarginstwh
\lipsum[4]
\clearpage
\end{document}
图像创建方式:
convert -density 150 -bordercolor LimeGreen -border 2 test.pdf[0] test1.png
convert -density 150 -bordercolor LimeGreen -border 2 test.pdf[1] test2.png
montage test1.png test2.png -geometry +2+2 -tile 2x1 test.png