5

I have the following code:

\begin{center}
\begin{figure}[H]
\begin{tabular}{lll}\vspace*{0.2 cm}
%1
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.3,-0.8) -- (1.8, 1.3);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
&
%2
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.6,-.1) -- (1.5, 1.8);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
&
%3
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (0.5, -0.6) -- (0.5, 1.6);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
\\
%
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.2, 1.5) -- (1.5, -0.3);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}%
&
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.3, 1.1) -- (1.2, -0.4);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}%
&
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.6, 0.5) -- (1.6, 0.5);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
\end{tabular}%
\caption{Casos de clasificadores}
\label{fig: xor_cases}
\end{figure}
\end{center}

Which produces the following figure: enter image description here

The upper left (first) subplot is misaligned with the rest of the row height-wise and I have no clue why. How can I fix this?

Also, I want to have a curly bracket that encompasses the first two columns. I tried using tikzmarkz but couldn't manage to get it working. Any ideas on how to do this?

0

2 Answers 2

6

The plot appears to be "misaligned" because it has a different bounding box, which gets computed automatically. In order to have the plots aligned, you may inject the same bounding box in each of the plots.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{float}
\begin{document}
\begin{figure}[H]
\centering\bgroup
\tikzset{cross/.style={minimum width=#1,
path picture={ \draw
            (path picture bounding box.south east) --
            (path picture bounding box.north west)
            (path picture bounding box.south west) --
            (path picture bounding box.north east);
}},every picture/.append style={remember picture,
execute at begin picture={%
\path[use as bounding box] (-0.8,-0.8) rectangle (2.4,2.4);}}}
\begin{tabular}{lll}
%1
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.3,-0.8) -- (1.8, 1.3);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
&
%2
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.6,-.1) -- (1.5, 1.8);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
&
%3
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (0.5, -0.6) -- (0.5, 1.6);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}
\\
%
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.2, 1.5) -- (1.5, -0.3);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\coordinate (L) at (-0.5,-0.5);
\end{tikzpicture}%
&
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.3, 1.1) -- (1.2, -0.4);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\coordinate (R) at (2.4,-0.5);
\end{tikzpicture}%
\begin{tikzpicture}[overlay]
\draw[thick,decorate,decoration=brace] (R) -- (L)
node[midway,below,font=\sffamily]{Curious koala bear};
\end{tikzpicture}
&
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (2,0) node[right] {$x_1$};
\draw[->] (0,-0.5) -- (0,2) node[above] {$x_2$};

\draw[dashed, -, red] (-0.6, 0.5) -- (1.6, 0.5);

% Circles and crosses
\draw[blue] (0,0) circle (0.175cm);
\draw[blue] (1,1) circle (0.175cm);
\draw (0,1) node[cross=4pt, red] {};
\draw (1,0) node[cross=4pt, red] {};
\end{tikzpicture}\\[0.4cm]
\end{tabular}%
\egroup
\caption{Casos de clasificadores}
\label{fig: xor_cases}
\end{figure}
\end{document}

enter image description here

4
  • Can I use \tikzset after \begin{document} in case I need to set this differently in other sections of my document? Feb 1, 2019 at 1:48
  • Any thoughts on how can I draw the curly bracket across subfigures in tabular @marmot? Feb 1, 2019 at 1:51
  • Updated the image, the curly bracket does not need to be that big as in my fatfingered sketch @marmot Feb 1, 2019 at 2:02
  • 1
    you got it, the answer is what I was looking for Feb 1, 2019 at 2:17
1

In case you look for a simpler TikZ code:

\documentclass[tikz]{standalone}
\tikzset{cross/.pic={
        \draw (-45:2mm)--(135:2mm) (45:2mm)--(225:2mm);
}}
\def\commompath{
    \draw[->] (-.5,0)--(2,0) node[right]{$x_1$};
    \draw[->] (0,-.5)--(0,2) node[above]{$x_2$};
    \draw[blue] (0,0) circle (.175) (1,1) circle (.175);
    \draw[red] (0,1) pic{cross} (1,0) pic{cross};
}
\begin{document}
\def\a{4cm}  \def\b{4cm} % for aligning parts
\begin{tikzpicture}

% 1
\begin{scope}[xshift=-\a]
\commompath
\draw[dashed,red] (-.3,-.8)--(1.8,1.3);
\end{scope}

% 2
\begin{scope}
\commompath
\draw[dashed,red] (-.6,-.1)--(1.5, 1.8);
\end{scope}

% 3
\begin{scope}[xshift=\a]
\commompath
\draw[dashed,red] (.5,-.6)--(.5, 1.6);
\end{scope}

% 4
\begin{scope}[xshift=-\a,yshift=-\b]
\commompath
\draw[dashed,red] (-.2,1.5)--(1.5,-.3);
\end{scope}

% 5
\begin{scope}[yshift=-\b]
\commompath
\draw[dashed,red] (-.3, 1.1)--(1.2,-.4);
\end{scope}

% 6
\begin{scope}[xshift=\a,yshift=-\b]
\commompath
\draw[dashed,red] (-.6,.5)--(1.6,.5);
\end{scope}

\end{tikzpicture}
\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 .