1

This is a legend that I need to make but I can't make the space between the columns work. They need to be evenly spaced without going into margin. I'm also interested to know how to make this in the caption as well.

\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
  • A big part of the problem comes from using \bf, which has been out of use for a while. But even if one fixes this, there are still minor issues. Yet things become much better if you have the two "allocated" cells on top of each other.
    – user194703
    Mar 29, 2020 at 2:02

1 Answer 1

2

This is a quickly written proposal. The main thing is to replace \bf by node font=\bfseries, and try to put things of similar width in the same columns. There is still room for improvement, though.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .