考虑这个简单的 tikz 树:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\begin{document}
\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}[]
\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode, cross out]{Good Afternoon}}
child{node[mynode]{Good Evening}}
\end{tikzpicture}
\end{document}
此代码产生以下内容:
然而,我以为“下午好”节点应该被划掉,因为有类似的东西这里。
我怎样才能让取消的‘X’出现在那个特定的节点上?
答案1
您需要,draw
同时放置cross out
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,decorations}
\begin{document}
\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}
\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode, cross out,draw]{Good Afternoon}}
child{node[mynode]{Good Evening}};
\end{tikzpicture}
\end{document}
如果您想要颜色,请使用draw=red
任何颜色。
答案2
这是基于杰西的回答但使用样式定义而不是嵌套tikzpicture
环境:
\documentclass[tikz]{standalone}
\usetikzlibrary{trees,shapes.misc}
\begin{document}
\begin{tikzpicture}[
mynode/.append style={text width=4em, align=center},
tcancel/.append style={draw=#1, cross out, inner sep=1pt},
]
\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode,tcancel=red]{Good Afternoon}}
child{node[mynode]{Good Evening}};
\end{tikzpicture}
\end{document}
答案3
这是定义宏的一个可能的解决方案\tcancel
。#1 = 首选颜色。#2 是内容。
\newcommand{\tcancel}[2][black]{%
\begin{tikzpicture}
\node[draw=#1,cross out,inner sep=1pt] (a){#2};
\end{tikzpicture}%
}
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\usetikzlibrary{shapes.misc}
\newcommand{\tcancel}[2][black]{%
\begin{tikzpicture}
\node[draw=#1,cross out,inner sep=1pt] (a){#2};
\end{tikzpicture}%
}
\begin{document}
\tikzstyle{mynode} = [text width=4em, text centered]
\begin{tikzpicture}[]
\node{My Root}
child{node[mynode]{Good Morning}}
child{node[mynode]{\tcancel[red]{Good Afternoon}}}
child{node[mynode]{Good Evening}};
\end{tikzpicture}
\end{document}