我想做以下事情:
- 蓝色节点和红色节点互相接触,并且它们的文本位于同一基线上
- 绿色节点位于它们下方 1pt,其右边缘与红色节点对齐。
我目前所拥有的并不令人满意。如果我更改字体或字体大小,绿色字体会不必要地移动,并且文本 1 和 2 的基线不一致。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (t1) [fill=red]
{text 1,};
\node [left=0pt of t1,fill=blue,text=white,draw=orange] (t2)
{slightly longer text};
\node [below left=0.5pt and -1.1cm of t1,fill=green,text=white,text width=.5\textwidth,align=left] (t3)
{a much longer text with some line breaks};
\end{tikzpicture}
\end{document}
我想我需要使用一些anchor
s 和base
键,但我需要一些帮助。
答案1
我不确定要解决什么问题,这样吗?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (t1) [fill=red, outer sep=0pt]
{text 1,};
\node [left=0pt of t1.base west, anchor=base east, fill=blue, text=white, draw=orange] (t2) {slightly longer text};
\node [below left = 1pt and 0pt of t1.south east, fill=green, text=white, text width=.5\textwidth, align=left, outer sep=0pt] (t3)
{a much longer text with some line breaks};
\end{tikzpicture}
\end{document}