问题描述
鉴于
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand*{\MyNode}[3][]{%
\begin{tikzpicture}
\node[#1] (A) at #2 {#3};
\node[isosceles triangle,
fill=yellow,
inner sep=10,
minimum height=1cm,
xshift=0.25cm] (T) at (A.east){};
\end{tikzpicture}%
}
\begin{document}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1cm, fill=yellow]{(0,0)}{\huge\textbf{\textsf{Education}}}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1cm, fill=yellow]{(0,0)}{\huge\textbf{\textsf{Work Experience}}}
\end{document}
生产
我正在尝试找到一种方法将两个形状节点粘在一起并赋予它们相同的高度。
我尝试过
我尝试更改节点的参数inner sep
,但似乎无法解决所有内部文本长度的问题。我进一步尝试修改第二个实例中的参数,但无法解决问题,修改似乎只会将三角形推向右侧。outer sep
isoceles triangle
minimum height
\MyNode
outer sep
有谁知道我怎样才能实现这个目标?
答案1
根据您的代码(我并不是说这是最好的解决方案):为三角形添加一个锚点以进行定位,然后将 更改为minimum height
。minimum width
虽然这听起来违反直觉,但它会改变您试图影响的三角形的方面。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand*{\MyNode}[3][]{%
\begin{tikzpicture}
\node[#1] (A) at #2 {#3};
\node[isosceles triangle,
fill=blue,
inner sep=10,
minimum width=1.4cm,
anchor=west,
xshift=-0.02cm
] (T) at (A.east){};
\end{tikzpicture}%
}
\begin{document}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1.4cm, fill=red]{(0,0)}{\huge\textbf{\textsf{Education}}}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1.4cm, fill=red]{(0,0)}{\huge\textbf{\textsf{Work Experience}}}
\end{document}
答案2
对我来说,当你可以用单一signal
形状定义形状时,为什么还要用两个形状来组成形状,而你的问题就不会发生:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,
shapes.symbols} % <---
\begin{document}
\begin{tikzpicture}[
node distance = 2mm,
S/.style = {signal, fill=yellow, signal to=east,
minimum height=3ex, text depth=0.25ex,
font=\sffamily\bfseries}
]
\node (n1) [S] {Education};
\node (n2) [right=of n1,S] {Work experience};
\end{tikzpicture}
\end{document}
答案3
替代解决方案,只需填充提示:
\documentclass{article}
\usepackage{tikz}
\newcommand*{\MyNode}[3][]{%
\begin{tikzpicture}
\node[#1] (A) at #2 {#3};
\fill[yellow] (A.north east) -- ([xshift=1.4cm]A.east) -- (A.south east) -- cycle;
\end{tikzpicture}%
}
\begin{document}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1cm, fill=yellow]{(0,0)}{\huge\textbf{\textsf{Education}}}
\MyNode[rectangle, inner sep=10, outer sep=0, minimum width=1cm, minimum height=1cm, fill=yellow]{(0,0)}{\huge\textbf{\textsf{Work Experience}}}
\end{document}