在 tikz 坐标中表达框属性

在 tikz 坐标中表达框属性

据我所知,任何 LaTeX 框都具有以下基本属性:

在此处输入图片描述

.. 和任何事物被包装进一个 LaTeX 盒子里。

因此,当我制作图片时tikz,它必须以某种方式包装到一个框中。事实上,当我使用它时,它似乎显示了这样一个heightbaseline。例如,以下代码:

\documentclass{report}

\usepackage[english]{babel}

\usepackage{tikz}
  \tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\newcommand{\mypicture}{\begin{tikzpicture}
        \node (a) at (0, 0) {\strut$a$};
        \node (b) at (30, 0) {\strut$b$};
        \draw[->] (a) .. controls (15, -20) and (30, -30) .. (b);
\end{tikzpicture}}

In my rather long, multilined text, I wish I could insert \mypicture{} just
as if it were something natural..

\end{document} 

生成:

在此处输入图片描述

.. 现在我想我的观点已经清楚了。上面的插入看起来一点也不自然,因为\mypicture框基线与节点基线不匹配(a)。如果匹配,两条线之间的垂直空间可能会受到影响。

如何纠正这个问题,而不用进行肮脏的手动调整\raisebox\vspace ETC。

tikz所有图片框属性如何用tikz坐标来表达?

答案1

在这种情况下,您必须告诉 TikZ 您希望它baseline位于何处。例如,您希望它位于您的(a)节点上。

以下是提供该功能的代码:

\documentclass{report}

\usepackage[english]{babel}

\usepackage{tikz}
  \tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\newcommand{\mypicture}{\begin{tikzpicture}[baseline=(a.base)]
        \node (a) at (0, 0) {\strut$a$};
        \node (b) at (30, 0) {\strut$b$};
        \draw[->] (a) .. controls (15, 20) and (30, 30) .. (b);
\end{tikzpicture}}

In my text, insert \mypicture{} just as if it were something natural..


\end{document}

其结果如下:

在此处输入图片描述

我希望这能有所帮助。

答案2

我需要的一般解决方案是两者的结合baseline以及精彩的关键use as bounding box:考虑一下:)

\documentclass[a4paper, 12pt]{report}

\usepackage{tikz}
    \tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\def\myfig{\begin{tikzpicture}[baseline=(base)] % choose baseline
    % box dimensions
    \path[draw, use as bounding box] (0, 0) rectangle (10, 15);
    % set baseline
    \coordinate (base) at (0, 5);
    % actual content
    \path[fill=blue] (0, 0) % a random path
        ..  controls (10, 10)
                 and (10, -10) ..
                     (10, 20) -- cycle;
    % visualize baseline
    \draw (0, 5) -- (10, 5);
\end{tikzpicture}}

Now I can define \emph{every} frea\myfig ng property of my tikz box!

\end{document}

在此处输入图片描述

唷!

相关内容