我正在尝试将一些公式放在cases
环境中equation*
,并将 tikz 图形并排放置,就像这张图一样:
然而,我使用了这个方法如何将算法和 tikz 绘图(不同类型的对象)并排放置在同一个浮动环境中?,我得到了这个:
我该如何调整?
代码:
\documentclass{article}
%\usepackage{xeCJK}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgf, tikz}
\usepackage{pgfplots}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
Hello, world!
\begin{figure}[!h]
\begin{subfigure}[b]{.5\linewidth}
\centering
\begin{equation*}
\begin{cases}
f(\sqrt{-\frac{a}{3}}) &< 0\\
f(0) &> 0\\
f(1) &< 0
\end{cases}
\end{equation*}
\end{subfigure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\begin{tikzpicture}[scale = 0.5]
\begin{axis}
\addplot {x};
\end{axis}
\end{tikzpicture}
\subcaption*{This plot shows us that ...}
\end{subfigure}
\end{figure}
\end{document}
答案1
您不需要不惜figure
一切代价:如果这是在equation*
环境中,那就使用它。
我看到的最简单的方法是使用带有m
类型列的两列表格。
\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgf, tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\begin{document}
\lipsum*[2]
\begin{equation*}
\begin{tabular}{
@{}
m{.5\textwidth}
@{}
m{.5\textwidth}
@{}
}
\centering
$\displaystyle
\begin{cases}
f(\sqrt{-\frac{a}{3}}) &< 0\\
f(0) &> 0\\
f(1) &< 0
\end{cases}
$
&
\centering
\begin{tikzpicture}[scale = 0.5]
\begin{axis}
\addplot {x};
\end{axis}
\end{tikzpicture}
\tabularnewline
&
This plot shows us that something happens
and we're very happy about it
\end{tabular}
\end{equation*}
\lipsum[3]
\end{document}
答案2
这是一个修复它的简单方法(更多信息请参阅注释的代码行):
\documentclass{article}
%\usepackage{xeCJK}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgf, tikz}
\usepackage{pgfplots}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
Hello, world!
\begin{figure}[!h]
\begin{subfigure}[c]{.5\linewidth}% use c(center) instead of b(bottom) for relative vertical alignement
\centering
\begin{equation*}
\begin{cases}
f(\sqrt{-\frac{a}{3}}) &< 0\\
f(0) &> 0\\
f(1) &< 0
\end{cases}
\end{equation*}
\vspace{5ex}%for fine tuning the vertical position of <cases>
\end{subfigure}%no empty line between subfigures environments
\begin{subfigure}[c]{.5\linewidth}% use c(center) instead of b(bottom) for relative vertical alignement
\centering
\begin{tikzpicture}[scale = 0.5]
\begin{axis}
\addplot {x};
\end{axis}
\end{tikzpicture}
\subcaption*{This plot shows us that ...}
\end{subfigure}
\end{figure}
\end{document}
答案3
使用tabularx
包的替代方法:
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{pgfplots}
\usepackage{caption}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[ht]
\begin{tabularx}{\textwidth}{X>{\centering\arraybackslash}X}
\[
\begin{cases}
f(\sqrt{-\frac{a}{3}}) & < 0 \\
f(0) & > 0 \\
f(1) & < 0
\end{cases}
\]
&
\begin{tikzpicture}[scale = 0.5]
\begin{axis}
\addplot {x};
\end{axis}
\end{tikzpicture} \\
& \caption*{This plot shows us that ...}
\end{tabularx}
\end{figure}
\lipsum[2]
\end{document}
上述 MWE 给出: