如何调整默认水平和垂直空间以满足以下要求(与 \parshape、自定义列表和图片间距相关)?

如何调整默认水平和垂直空间以满足以下要求(与 \parshape、自定义列表和图片间距相关)?

要求:

  1. 文档中页面的高度不应受恒定长度的限制(但页面宽度应受限制)。
  2. 段落中的每一行都应比该段落的前一行缩进更多(按恒定长度),并且每个段落的第一行根本不缩进(每个连续行的缩进按恒定长度增加)。

OUTPUT APPROXIMATION: 1 2 3 123456789012345678901234567890 <<< PARAGRAPH WIDTH This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4.\par This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4.

  1. 放置在段落内任何一行下方的图片都应缩进,就好像它(图片)是下一行一样。但是,段落中另一张图片后面的图片应与该图片(其后面的图片)完全缩进。段落中图片后面的第一行应与该图片具有相同的缩进。

OUTPUT APPROXIMATION: 1 2 3 123456789012345678901234567890 <<< PARAGRAPH WIDTH This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4. | O O | |\ ^ /| <<< PICTURE (INDENTED AS A LINE OF PARAGRAPH) | --- | _____ /O ^ O\ | --- | <<< PICTURE (SAME INDENT AS PREVIOUS PICTURE) \_____/ This is sentence 5. This is sentence 6.

  1. 上述放置在段落内的列表应使其项目本身的行为与那些段落相似,不同之处在于,项目的第一行不是从零缩进开始(就像段落的第一行一样),而应该从比项目前一行更大的缩进开始(除非该行属于同一列表的另一个项目,在这种情况下两个项目的缩进相同)。

OUTPUT APPROXIMATION: 1 2 3 123456789012345678901234567890 <<< PARAGRAPH WIDTH This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4: 1. This is item 1. This <<< LIST LABEL IS INDENTED AS is still item 1. A LINE OF PARAGRAPH Item 1 again. POST-LABEL LINE-INDENTS BEHAVE 2. This is item 2. This AS USUAL BUT WITH | is still item 2: LABEL WIDTH ADDED TO EACH | a) This is item <<< SUB-ITEM AFTER ITEM LINE BEHAVES | "a". Still AS IF IT WERE ITEM AFTER | item "a". PARAGRAPH LINE | b) This is item | "b". This is sentence 5. This is sentence 6.

  1. 每个段落、列表项或图片周围都应该有可选的边框(允许段落、列表项和图片由水平线分隔,以及允许图片中包含的方程式以宽垂直线开始)。
  2. 段落之间、段落与图片之间或图片之间的垂直间距应等于段落的行间距(应在整个文档中保持一致,但下面有一个例外)。
  3. 如果一个段落或图片(仅包含公式或文本)完全(或几乎完全)由比前一个段落或图片更大或更小的字体组成,则它们之间的垂直间距应分开:使得垂直间距的一半取决于上一个段落或图片的字体大小并包含在其中(在该段落或图片的框架内),而垂直间距的另一半(同样)取决于下一个段落或图片的字体大小并(同样)包含在其中(这种混合垂直间距的每一半都应包含在其各自的段落或图片内,使得较大字体的垂直空间保持在该字体的文本的结构范围内,较小字体也是如此)。

OUTPUT APPROXIMATION: large font size (20pt) <<< PARAGRAPH 1 | <<< LARGE FONT-SIZE INTERLINE-SPACING ---------------------- <<< END OF PARAGRAPH-1 FRAME ---------------------- <<< START OF PARAGRAPH-2 FRAME | <<< NORMAL FONT-SIZE INTERLINE-SPACING normal font size (10pt) <<< PARAGRAPH 2


让我们从代码示例开始。它有几个问题:(1)很难将数学方程式节点的边框定位在前一个段落行的边框之后(或将其定位在与该行相距行间距的位置),(2)如果指定了 25mm(缩进 15mm 后段落最后一行的剩余长度),则数学方程式节点的边框与页面的右侧边界重叠(所以我不知道要对 25mm 加多少或减多少才能使数学方程式节点的边框接触而不与页面边框重叠),(3)数学方程式节点的边框也与页面的底部边界重叠。

\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \path node[inner sep=0,draw,text width=40mm,anchor=north west]
      { \parbox{\hsize}
          { \parshape 4 0mm 40mm 5mm 35mm 10mm 30mm 15mm 25mm
            \fboxrule0.1pt
            \fboxsep0pt
            \fbox{hello world}\newline
            \fbox{hello world}\newline
            \fbox{hello world}\newline
            % FOLLOWING DIM EXPRESSION IS NOT ENOUGH TO ALIGN THE NODE FRAME EXACTLY BELOW THE \fbox OF THE PARAGRAPH-LINE (NODE FRAME IS SLIGHTLY HIGHER THAN THE \fbox FRAME)
            \vspace{\dimexpr-\lineskip-\baselineskip+0.1pt}
            \begin{tikzpicture}
            % 25mm (WIDTH OF LAST LINE, CONSIDERING INDENT OF 15mm) IS TOO WIDE, SO THE NODE FRAME OVERLAPS WITH THE PAGE FRAME; 24mm IS NOT APPROPRIATE WIDTH TO ALIGN THE NODE FRAME AT DOCUMENT BOUND WITHOUT WITHOUT OVERLAP
              \path node[draw,text width=24mm]
                { \parbox{\hsize}
                    { \begin{gather*}
                        2+2=4
                      \end{gather*}
                    }
                };
            \end{tikzpicture}
          }
      };
  \end{tikzpicture}
\end{document}

你可以用自己的方法彻底修改此代码示例,使其与原始代码完全不同。我关心的是使上述条件发挥作用。


进步:

更新:此答案(来自 egreg)解决了如何将数学方程节点框架定位在框架正下方,\fbox方法是将其减小\newline\vspace{\dimexpr-\lineskip-\baselineskip+0.1pt}\vspace{-\lineskip}\newline。但是,在这些框架之间生成等于行间距的垂直空间仍然是未解决的问题。我想我们可以使用1ex或字体大小相关的某些东西来生成垂直空间,而我们没有可用的行间距长度。让我们将其设为 1ex \vspace{\dimexpr-\lineskip+1ex}\newline:。

更新:(大卫卡莱尔建议)除了使用standalone带有tikz裁剪页面高度选项的类之外,\pdfpageheight还可以使用。

更新:有人建议(由 marmot 提出)不要tikz直接嵌套图片,而是将它们保存在盒子中(以避免混淆tikz,从而避免意外行为;tikz不希望图片环境直接嵌套在其他图片环境中,这是我从提供的链接中得出的结论)。

更新:节点框架对齐方面取得了很大进展。事实证明,当您将其设置inner sep为零时,text width从框架左侧的中间开始并延伸到框架右侧的中间。文本高度也类似:文本从框架顶部的中间开始并延伸到框架底部的中间。这需要内部节点text width“知道”外部节点的line width,从而产生了复杂性,这是可以避免的。(见这是 marmot 的回答

答案1

我的建议是先从基本要求开始,然后先实现这些要求,然后再添加更高级的功能,比如装箱。同样,根据文档内容指定 PDF 页面高度的方法已在网站上的几个现有答案中介绍过,如问题下的评论中所述。

据我所知,这可能只是实现基本的缩进和列表布局的开始。

请注意,由于没有引入额外的框层,因此不存在\lineskip间距问题,TeX 的标准换行可确保整个行距均匀。

在此处输入图片描述

\documentclass{article}
\setlength\textheight{2\textheight}
\pdfpageheight2\paperheight
\newdimen\zzindent
\setlength\parindent{0pt}

\makeatletter

\setlength\zzindent{5mm}
\def\setpshape#1{\zpshape{0}{#1}{\the\dimexpr\linewidth-#1\relax}{}}
\def\zpshape#1#2#3#4{%
\ifdim#2<\linewidth
\edef\zztmp{%
\noexpand\zpshape
{\the\numexpr#1+1\relax}%
{\the\dimexpr#2+\zzindent}%
{\the\dimexpr#3-\zzindent}%
{#4 #2 #3}}\zztmp
\else
\xdef\zcurrentshape{#1 #4 }%
\parshape#1 #4 %
\fi}

\def\enumerate{%
\ifhmode
\par
\endgroup
\let\endenumerate\hendenumerate
\everypar\expandafter{\expandafter\setpshape\expandafter{\the\dimexpr\prevgraf\zzindent\relax}}%
\else
\let\endenumerate\vendenumerate
\fi
\def\item{\par\refstepcounter{enumi}\theenumi. }%
}

\def\hendenumerate{\par
\def\par{\endgraf\everypar{\setpshape{0pt}}\let\par\endgraf}%
\ignorespacesafterend\begingroup\def\@currenvir{enumerate}}

\def\vendenumerate{\par}




\begin{document}

\everypar{\setpshape{0pt}}

one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 


one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 



one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five
\begin{enumerate}% in para list
\item aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
\item aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
\end{enumerate}
% text after in para list
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 


zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz
zzz zzz zzz zzz zzz zzz zzz zzz

\begin{enumerate}% par list starts in vmode
\item aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
\item aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
  bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa bbb ccc 
\end{enumerate}
% text after  par list
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 
one two three four five one two three four five one two three four five 

\end{document}

答案2

如何避免嵌套tikzpicture

\documentclass[tikz]{standalone}

\usepackage{amsmath}
\usepackage{tikz}

\newlength\innerPicLineWidth
\setlength\innerPicLineWidth{0.8pt}
\newlength\outerPicLineWidth
\setlength\outerPicLineWidth{1.5pt}

% SAVE INNER PICTURE IN A BOX (INSTEAD OF NESTING DIRECTLY;
%  DIRECT NESTING HAS COMPLICATIONS)
\newsavebox\picbox
\sbox\picbox
  {% MAKE SURE NO SPACE IS PRESENT HERE (OTHERWISE FRAMES OVERLAP)
    \begin{tikzpicture}
      \path node
        [ draw=red,
          %
          % IF inner sep IS HALF THE line width, NODE CONTENTS
          %  DON'T OVERLAP WITH THE FRAME AND NODE WIDTH IS
          %   (line width * 2 + text width), WHICH IS INTUITIVE
          %
          % IF inner sep IS ZERO, CONTENTS OF A NODE OVERLAP WITH
          %  ITS FRAME AND NODE WIDTH IS (line width + text width)
          %
          % THIS HAS IMPLICATIONS: IF OUTER AND INNER NODES BOTH
          %  HAVE inner sep SET TO ZERO, STRETCHING INNER NODE TO
          %   FILL OUTER NODE WITHOUT OVERLAPPING WITH OUTER
          %    NODE'S FRAME WOULD REQUIRE INNER NODE'S text width
          %     TO "KNOW" OUTER NODE'S line width (BUT THIS CAN BE
          %      AVOIDED BY SETTING inner sep OF EACH NODE TO HALF
          %       OF ITS line width)
          %
          inner sep=\innerPicLineWidth/2,
          line width=\innerPicLineWidth,
          text width=25mm-\innerPicLineWidth*2
        ]
        { \parbox{\hsize}
            { \begin{gather*}
                2+2=4
              \end{gather*}
            }
        };
    \end{tikzpicture}
  }

\begin{document}
  \begin{tikzpicture}
    \path node
      [ draw=blue,
        inner sep=\outerPicLineWidth/2,
        line width=\outerPicLineWidth,
        text width=40mm
      ]
      { \parbox{\hsize}
          { \parshape 4 0mm 40mm 5mm 35mm 10mm 30mm 15mm 25mm
            \fboxrule0.1pt
            \fboxsep0pt
            \fbox{hello world}\newline
            \fbox{hello world}\newline
            \fbox{hello world}
            % GENERATE 1ex SPACE INSTEAD OF \lineskip SPACE
            %  BETWEEN INNER NODE FRAME AND \fbox FRAME
            \vspace{\dimexpr-\lineskip+1ex}\newline
            \usebox\picbox
          }
      };
  \end{tikzpicture}
\end{document}

整个外部节点 外节点的左上角 内部节点的右上角 内部节点的左下角

相关内容