如何获取 Tikz 绘图的侧面标题?
如果我尝试使用 SCfigure,我的绘图会与标题重叠。
这是我使用 SCfigure 绘制的图像:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{sidecap}
\begin{document}
\begin{SCfigure} [b]
\centering
\begin{tikzpicture}[scale=0.5]
\draw (-1,-3) -- (-1,3) -- (-0.7,3) -- (-0.7, -3) -- cycle;
\draw (1,3) -- (1,-3) -- (0.7,-3) -- (0.7, 3) -- cycle;
\fill[black!15] (1,3) -- (1,-3) -- (0.7,-3) -- (0.7, 3) -- cycle;
\fill[black!15] (-1,-3) -- (-1,3) -- (-0.7,3) -- (-0.7, -3) -- cycle;
\draw [<->] (-0.68,0) --(0.68,0);
\draw (0,0) node[anchor=north] {$h$};
\draw [<-] (1.01,-0.5) --(2.8,-0.5);
\draw (1.9,-0.5) node[anchor=north] {\small{K}};
\draw (1.75,0.5) circle (0.7);
\draw (2.2,2.5) circle (0.7);
\draw (-2,1.7) circle (0.7);
\draw (-1.75,0) circle (0.7);
\draw (-2.3,-1.6) circle (0.7);
\draw (2,-1.98) circle (0.7);
\draw [<->] (2.69,-1.98) --(1.31,-1.98);
\draw (2,-1.98) node[anchor=north] {$\sigma$};
\end{tikzpicture}
\caption{I would love to have this caption on the left of my drawing :}
\label{entropic1}
\end{SCfigure}
\end{document}
答案1
- 正如上述评论所述,图表(或表格)侧面的标题旨在
SCfigure
- 您可以设置与图像相关的标题的垂直位置
\sidecaptionvpos{figure}{m}
(m 为中间、t 为顶部、b 为底部 /默认/) - 使用选项,您可以确定图像和标题宽度之间的比例(默认为 1)
(红线仅表示页面布局)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[leftcaption]{sidecap}
\sidecaptionvpos{figure}{m}
\usepackage{tikz}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{SCfigure}[0.8][htb]
\centering
\begin{tikzpicture}%[baseline]
\draw[fill=black!15] (-1,-3) -- (-1,3) -- (-0.7,3) -- (-0.7, -3) -- cycle;
\draw[fill=black!15] (1,3) -- (1,-3) -- (0.7,-3) -- (0.7, 3) -- cycle;
\draw [<->] (-0.68,0) -- node[anchor=north] {$h$}(0.68,0);
\draw [<-] (1.01,-0.5) -- node[anchor=north] {$K$}(2.8,-0.5);
\draw (1.75,0.5) circle (0.7cm)
(2.2,2.5) circle (0.7cm)
(2,-1.8) circle (0.7cm);
(-2,1.7) circle (0.7cm);
(-1.75,0) circle (0.7cm);
(-2.3,-1.6) circle (0.7cm);
\draw [<->] (2.69,-1.8) -- node[anchor=north] {$\sigma$}(1.31,-1.8);
\end{tikzpicture}
\caption{I would love to have this caption on the left of my drawing :)}
\label{plates1}
\end{SCfigure}
\end{document}
在上面的代码中,我也使tikzpicture
代码更短。如您所见,不需要缩放图像。
答案2
您的语法有误。后面的第一个选项\begin{SCfigure}
应该是一个数字(标题的相对大小)。您有[b]
。
这是正确的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage[leftcaption]{sidecap}
\begin{document}
\begin{SCfigure}[0.5][b]
\centering
\begin{tikzpicture}[scale=1]
\draw (-1,-3) -- (-1,3) -- (-0.7,3) -- (-0.7, -3) -- cycle;
\draw (1,3) -- (1,-3) -- (0.7,-3) -- (0.7, 3) -- cycle;
\fill[black!15] (1,3) -- (1,-3) -- (0.7,-3) -- (0.7, 3) -- cycle;
\fill[black!15] (-1,-3) -- (-1,3) -- (-0.7,3) -- (-0.7, -3) -- cycle;
\draw [<->] (-0.68,0) --(0.68,0);
\draw (0,0) node[anchor=north] {$h$};
\draw [<-] (1.01,-0.5) --(2.8,-0.5);
\draw (1.9,-0.5) node[anchor=north] {\small{K}};
\draw (1.75,0.5) circle (0.7);
\draw (2.2,2.5) circle (0.7);
\draw (-2,1.7) circle (0.7);
\draw (-1.75,0) circle (0.7);
\draw (-2.3,-1.6) circle (0.7);
\draw (2,-1.98) circle (0.7);
\draw [<->] (2.69,-1.98) --(1.31,-1.98);
\draw (2,-1.98) node[anchor=north] {$\sigma$};
\end{tikzpicture}
\caption{I would love to have this caption on the left of my drawing} \label{entropic1}
\end{SCfigure}
\end{document}
其结果为: