我有以下代码:
\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}
左上角(第一个)子图与行高其余部分未对齐,我不知道原因。我该如何修复?
另外,我想要一个包含前两列的大括号。我尝试使用tikzmarkz
,但无法让它工作。有什么想法可以做到这一点吗?
答案1
该图似乎“未对齐”,因为它具有不同的边界框,该边界框会自动计算。为了使图对齐,您可以在每个图中注入相同的边界框。
\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}
答案2
如果你寻找更简单的 TikZ 代码:
\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}