baselinestretch 无法与 \tikz inline 配合使用(并且 \tikz inline 通常不占用行距)

baselinestretch 无法与 \tikz inline 配合使用(并且 \tikz inline 通常不占用行距)

当使用\tikz内联时,下面说:

\documentclass{article}
\renewcommand{\baselinestretch}{1.2}

\usepackage{tikz}

\begin{document}

He moonlight difficult engrossed an it sportsmen. Interested has all devonshire difficulty gay assistance joy. Unaffected at ye of compliment alteration to. Place voice no arise along to. Parlors waiting so against me no. Wishing calling are warrant settled was luckily. Express besides it present if at an opinion visitor. Questions explained agreeable preferred strangers too him her son. Set put shyness offices his females him distant. Improve has message besides shy himself cheered however how son. Quick judge other leave ask first chief her. Indeed or remark \tikz[baseline=-0.5ex]{ \draw [|-|] (0,-1) rectangle (3,2); } silent seemed narrow be. Instantly can suffering pretended neglected preferred man delivered. Perhaps fertile brandon do imagine to cordial cottage. On insensible possession oh particular attachment at excellence in. The books arose but miles happy she. It building contempt or interest children mistress of unlocked no. Offending she contained mrs led listening resembled. Delicate marianne absolute men dashwood landlord and offended. Suppose cottage between and way. Minuter him own clothes but observe country. Agreement far boy otherwise rapturous incommode favourite.

\end{document}

我们看到:

在此处输入图片描述

我们看到 Tikz 图片与上方和下方的线条齐平。

是否可以采取任何措施让 tikz 图片表现得好像它确实是一个真正的内联字符,并使其上方和下方的间距等于行间间距。

我有一个基于 \tikz 的通用命令,我正在使用它,因此在上面和下面使用 \vspace 将不起作用,因为如果插入到第一行,顶部会有一个不需要的额外填充(请注意,行分隔不会在顶部添加填充,例如在列表中,对于第一行)。

答案1

如上所述,这实际上不是 TikZ 的问题,而是任何产生比正常线更高的物体的问题。

尽管如此,这里有一些想法可以帮助我们自动解决这个问题。

首先,有键above space和,below space应该用作tikzpicture环境或\tikz宏的选项(或作为样式的一部分every picture。它们将给定的长度添加到图片的顶部或底部。它们都可以与相同的距离一起使用above and below space

其次,它的pad above and below作用基本相同,但前提是图片的高度大于\baselineskip。我已为其指定默认值,以.25*\baselineskip添加上方和下方。您可以随意更改它或使用明确的值。

一旦可以真正区分太高(高度太高)的图片和/或太深(深度太深)的图片,并区别对待它们。

代码

\documentclass{article}
\renewcommand{\baselinestretch}{1.2}
\usepackage{tikz}
\tikzset{
  above space/.style={execute at end picture={\path[reset cm]([yshift={#1}]current bounding box.north);}},
  below space/.style={execute at end picture={\path[reset cm]([yshift={-(#1)}]current bounding box.south);}},
  above and below space/.style={above space={#1}, below space={#1}}}
\makeatletter
\tikzset{
  pad above and below/.default=.25*\baselineskip, % maybe factor .5?
  pad above and below/.style={
    execute at end picture={%
      \pgf@process{\pgfpointdiff{\pgfpointanchor{current bounding box}{south}}
                                {\pgfpointanchor{current bounding box}{north}}}%
      \ifdim\pgf@y>\baselineskip\relax
        \begingroup % PGF of % \path[reset cm]([yshift={#1}]current bounding box.north);
          \pgftransformreset % \path[reset cm]([yshift={-(#1)}]current bounding box.south);
          \pgfpathmoveto{\pgfpointadd{\pgfpoint{+0pt}{#1}}{\pgfpointanchor{current bounding box}{north}}}%
          \pgfpathmoveto{\pgfpointadd{\pgfpoint{+0pt}{-(#1)}}{\pgfpointanchor{current bounding box}{south}}}%
          \pgfusepath{discard}%
        \endgroup
      \fi}}}
\makeatother
\begin{document}

He moonlight difficult engrossed an it sportsmen. Interested has all devonshire difficulty gay assistance joy. Unaffected at ye of compliment alteration to. Place voice no arise along to. Parlors waiting so against me no. Wishing calling are warrant settled was luckily. Express besides it present if at an opinion visitor. Questions explained agreeable preferred strangers too him her son. Set put shyness offices his females him distant. Improve has message besides shy himself cheered however how son. Quick judge other leave ask first chief her. Indeed or remark
\tikz[baseline=-0.5ex, pad above and below]\draw [|-|] (0,-1) rectangle (3,2);
silent seemed narrow be. Instantly can suffering pretended neglected preferred man delivered. Perhaps fertile brandon do imagine to cordial cottage. On insensible possession oh particular attachment at excellence in. The books arose but miles happy she. It building contempt or interest children mistress of unlocked no. Offending she contained mrs led listening resembled. Delicate marianne absolute men dashwood landlord and offended. Suppose cottage between and way. Minuter him own clothes but observe country. Agreement far boy otherwise rapturous incommode favourite.

\end{document}

输出

在此处输入图片描述

答案2

如果我理解正确的话,那么你

在此处输入图片描述

\documentclass{article}
\renewcommand{\baselinestretch}{1.2}
\usepackage{tikz}

\begin{document}

He moonlight difficult engrossed an it sportsmen. Interested has all devonshire difficulty gay assistance joy. Unaffected at ye of compliment alteration to. Place voice no arise along to. Parlors waiting so against me no. Wishing calling are warrant settled was luckily. Express besides it present if at an opinion visitor. Questions explained agreeable preferred strangers too him her son. Set put shyness offices his females him distant. Improve has message besides shy himself cheered however how son. Quick judge other leave ask first chief her. Indeed or remark 
    \tikz[baseline=-0.5ex]{\draw (0,-1) rectangle (3,2); 
                           \path (0,-1.16) -- (0,2.16);} % <--- add vertical space
silent seemed narrow be. Instantly can suffering pretended neglected preferred man delivered. Perhaps fertile brandon do imagine to cordial cottage. On insensible possession oh particular attachment at excellence in. The books arose but miles happy she. It building contempt or interest children mistress of unlocked no. Offending she contained mrs led listening resembled. Delicate marianne absolute men dashwood landlord and offended. Suppose cottage between and way. Minuter him own clothes but observe country. Agreement far boy otherwise rapturous incommode favourite.

\end{document}

相关内容