这是我需要制作的图例,但我无法让列之间的空间发挥作用。它们需要均匀分布,而不能占用边距。我也想知道如何在标题中做到这一点。
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{automata, backgrounds,calc,shapes}
\usepackage{subfig}
\makeatletter
\tikzset{circle split part fill/.style args={#1,#2}{%
alias=tmp@name,
postaction={%
insert path={
\pgfextra{%
\pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
{\pgfpointanchor{\pgf@node@name}{east}}%
\pgfmathsetmacro\insiderad{\pgf@x}
\fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
(0:180:\insiderad-\pgflinewidth)--cycle;
\fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected]) arc
(180:360:\insiderad-\pgflinewidth)--cycle; % \end{scope}
}}}}}
\makeatother
\begin{document}
\definecolor{yes}{RGB}{255,51,76}
\definecolor{no}{RGB}{161,251,251}
\begin{figure}[ht]
\centering
\tikzset{shorten >=1pt,
node distance=.55cm,
font = \scriptsize,
auto,%on grid
state/.style = {shape=circle,thick,draw,minimum width=+1.7ex,minimum height=+1.4ex,inner sep=+.1pt}
}
\begin{tikzpicture}% note that \tiny gets inherited from above
\matrix[column sep=.2ex,draw]{ \draw[->,thick] (-1.2em,1em) -- (-1.2em,0); \draw[->,thick] (-1em,0.5em) -- (0,0.5em)
node[right] {\bf go forward};
&
\draw[<-, thick] (-1.2em,1em) -- (-1.2em,0); \draw[<-,thick] (-1em,0.5em) -- (0,0.5em)
node[right] {\bf{go backward}};
& \draw (-0.2em,0) edge [thick,in=150,out=80,loop] (-0.2em,0);
\path (0,0.5em) node[thick, right] {\bf{stay}};
& \node[state,fill=yes,label=right:\bf{yes}]{};\\
& \node[state,fill=no,label=right: \bf{no}]{};
& \node[state,circle split part fill={no,yes},label=right:\bf{Both}]{};
& \node[state,fill = gray,label=right:\bf{allocated in previous cohorts}]{};
& \node[state,fill = white,label=right: \bf{not allocated yet}]{};
;\\
};
\end{tikzpicture}
\caption{my figure}
\end{figure}
\end{document}
答案1
这是一个快速编写的提案。主要内容是用 替换\bf
,node font=\bfseries
并尝试将宽度相似的元素放在同一列中。不过仍有改进的空间。
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{automata, backgrounds,calc,shapes}
\usepackage{subfig}
\makeatletter
\tikzset{circle split part fill/.style args={#1,#2}{%
alias=tmp@name,
postaction={%
insert path={
\pgfextra{%
\pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
{\pgfpointanchor{\pgf@node@name}{east}}%
\pgfmathsetmacro\insiderad{\pgf@x}
\fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
(0:180:\insiderad-\pgflinewidth)--cycle;
\fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected]) arc
(180:360:\insiderad-\pgflinewidth)--cycle; % \end{scope}
}}}}}
\makeatother
\begin{document}
\definecolor{yes}{RGB}{255,51,76}
\definecolor{no}{RGB}{161,251,251}
\begin{figure}[ht]
\centering
\tikzset{shorten >=1pt,
node distance=.55cm,
font = \scriptsize,
auto,%on grid
state/.style = {shape=circle,thick,draw,minimum width=+1.7ex,minimum height=+1.4ex,inner sep=+.1pt}
}
\begin{tikzpicture}% note that \tiny gets inherited from above
\matrix[column sep=.2ex,draw,nodes={node font=\bfseries},every label/.append
style={node font=\bfseries}]{
\draw[->,thick] (-1.2em,1em) -- (-1.2em,0); \draw[->,thick] (-1em,0.5em) -- (0,0.5em)
node[right] {go forward};
& \draw (-0.2em,0) edge [thick,in=150,out=80,loop] (-0.2em,0);
\path (0,0.5em) node[right] {stay~~};
& \path (-1ex,0.5em) node[state,fill=no,label=right: no]{};
& \path (-1ex,0.5em) node[state,fill = gray,label=right:allocated in previous cohorts]{};\\
\draw[<-, thick] (-1.2em,1em) -- (-1.2em,0); \draw[<-,thick] (-1em,0.5em) -- (0,0.5em)
node[right] {go backward};
& \path (-1ex,0.5em) node[state,fill=yes,label=right:yes]{};
& \path (-1ex,0.5em) node[state,circle split part fill={no,yes},label=right:Both~~]{};
& \path (-1ex,0.5em) node[state,fill = white,label=right:not allocated yet]{};
;\\
};
\end{tikzpicture}
\caption{my figure}
\end{figure}
\end{document}