![如何在特定 Tikzpicture 的段落开头添加 Baselineskip](https://linux22.com/image/438253/%E5%A6%82%E4%BD%95%E5%9C%A8%E7%89%B9%E5%AE%9A%20Tikzpicture%20%E7%9A%84%E6%AE%B5%E8%90%BD%E5%BC%80%E5%A4%B4%E6%B7%BB%E5%8A%A0%20Baselineskip.png)
此处提出的问题是希望插入一个图形并将其包裹在自定义的 Tikzpicture 中
考虑以下代码
\documentclass[border=1cm]{book}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage[justification=centering]{caption}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{shadings}
\begin{document}
\thispagestyle{empty}
\definecolor{pylight}{RGB}{247, 235, 205}
\definecolor{py}{RGB}{243, 224, 181}
\definecolor{pydark}{RGB}{221, 182, 110}
\definecolor{pyhighlight}{RGB}{254, 235, 204}
\pgfdeclareverticalshading{parchment}{100bp}{%
color(0bp)=(pydark);
color(25bp)=(pydark);
color(30bp)=(py);
color(50bp)=(pylight);
color(70bp)=(py);
color(75bp)=(pydark);
color(100bp)=(pydark)%
}
\pgfdeclareradialshading{rparchment}{\pgfpoint{0cm}{0cm}}{%
color(0bp)=(pylight);
color(13bp)=(pylight);
color(20bp)=(py);
color(40bp)=(pydark);
color(60bp)=(pydark!50!black);
color(100bp)=(black)%
}
\tikzset{
pencildraw/.style={%
decorate, decoration={%
random steps, segment length=1.1ex, amplitude=.5ex%
}
},
drop shadow/.style={
blur shadow={%
shadow xshift=.5pt,
shadow yshift=-.5pt,
shadow blur steps=9,
shadow blur extra rounding=1.5pt%
},
},
parchment fill/.style={
pencildraw, fill=pyhighlight,
postaction={shading=parchment, opacity=1},
postaction={shading=rparchment, opacity=.7}
}
}
\begin{tikzpicture}
\shade node[preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},parchment fill, drop shadow,
inner sep=5mm]
{\parbox{0.87\textwidth}{\fontsize{13}{16}\selectfont
\hangindent=\dimexpr 0.2\textwidth+\columnsep\relax
\hangafter=-4
\noindent\llap{\raisebox{\dimexpr 0.6\baselineskip-\height}[0pt][0pt]% overlap indentation
{\includegraphics[width=0.2\textwidth]{example-image-a}}\hspace{\columnsep}}%
\textbf{\textit{\lipsum[2]}}}} ;
\end{tikzpicture}
\end{document}
产生输出
我想将段落稍微降低一些,以便它不会从与插入图像顶部相同的高度开始,并希望 \vspace{\baselineskip}
在之前立即插入\lipsum[2]
可能会解决问题;但遗憾的是,事实并非如此。
当我添加代码时
\begin{tikzpicture}
\shade node[preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},parchment fill, drop shadow,
inner sep=5mm]
{\parbox{0.87\textwidth}{\fontsize{13}{16}\selectfont
\hangindent=\dimexpr 0.2\textwidth+\columnsep\relax
\hangafter=-4
\noindent\llap{\raisebox{\dimexpr 0.6\baselineskip-\height}[0pt][0pt]% overlap indentation
{\includegraphics[width=0.2\textwidth]{example-image-a}}\hspace{\columnsep}}%
\textbf{\textit{\vspace{\baselineskip}\lipsum[2]}}}} ;
\end{tikzpicture}
我得到的盒子是这样的:
我不明白为什么baselineskip
似乎出现在第一行之后而不是之前。我通过移至 \vspace{\baselineskip}
其他地方没有成功。
问题:是否有一种简单的方法(使用给定的代码)将段落的开头降低指定的量(例如,a baselineskip
),同时将图像保持在固定位置?根据实际段落的长度,我可能想要增加或减少段落降低的长度---因此,我希望通过一两个命令来实现这一点,而不是通过“调整”现有代码中的一些数值组合来实现。
谢谢。
答案1
我定义了一个新的长度\zzz
,并将其设置为 10pt,
增加
\raisebox
图像的尺寸\zzz
,使其悬空在文本上方。添加
\vspace{\zzz}
以将整个构造向下移动,从而恢复图像的位置。将
\hangafter
-4 改为 -3,这样就只需要三条线切入,因为图像所需的空间较少。
\documentclass[border=1cm]{book}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage[justification=centering]{caption}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{shadings}
\newlength\zzz
\setlength\zzz{10pt}
\begin{document}
\thispagestyle{empty}
\definecolor{pylight}{RGB}{247, 235, 205}
\definecolor{py}{RGB}{243, 224, 181}
\definecolor{pydark}{RGB}{221, 182, 110}
\definecolor{pyhighlight}{RGB}{254, 235, 204}
\pgfdeclareverticalshading{parchment}{100bp}{%
color(0bp)=(pydark);
color(25bp)=(pydark);
color(30bp)=(py);
color(50bp)=(pylight);
color(70bp)=(py);
color(75bp)=(pydark);
color(100bp)=(pydark)%
}
\pgfdeclareradialshading{rparchment}{\pgfpoint{0cm}{0cm}}{%
color(0bp)=(pylight);
color(13bp)=(pylight);
color(20bp)=(py);
color(40bp)=(pydark);
color(60bp)=(pydark!50!black);
color(100bp)=(black)%
}
\tikzset{
pencildraw/.style={%
decorate, decoration={%
random steps, segment length=1.1ex, amplitude=.5ex%
}
},
drop shadow/.style={
blur shadow={%
shadow xshift=.5pt,
shadow yshift=-.5pt,
shadow blur steps=9,
shadow blur extra rounding=1.5pt%
},
},
parchment fill/.style={
pencildraw, fill=pyhighlight,
postaction={shading=parchment, opacity=1},
postaction={shading=rparchment, opacity=.7}
}
}
\begin{tikzpicture}
\shade node[preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},parchment fill, drop shadow,
inner sep=5mm]
{\parbox{0.87\textwidth}{\fontsize{13}{16}\selectfont
\vspace{\zzz}%
\hangindent=\dimexpr 0.2\textwidth+\columnsep\relax
\hangafter=-3
\noindent\llap{\raisebox{\dimexpr \zzz+0.6\baselineskip-\height}[0pt][0pt]% overlap indentation
{\includegraphics[width=0.2\textwidth]{example-image-a}}\hspace{\columnsep}}%
\textbf{\textit{\lipsum[2]}}}} ;
\end{tikzpicture}
\end{document}