![在 tikz 座標中表達框屬性](https://rvso.com/image/328832/%E5%9C%A8%20tikz%20%E5%BA%A7%E6%A8%99%E4%B8%AD%E8%A1%A8%E9%81%94%E6%A1%86%E5%B1%AC%E6%80%A7.png)
根據我的理解,任何 LaTeX 框都顯示出這樣的基本屬性:
.. 和任何事物被包裹在一個乳膠盒子裡。
所以,當我創作一tikz
幅畫時,它必須以某種方式包裝到一個盒子裡。確實,我用的時候好像顯示這樣的aheight
和a 。baseline
例如,這段程式碼:
\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}
唷!