我想通过在左上角添加字母标识符(如(a)
等)来注释我在其他软件中设计的子图。我正在使用callouts
由于我已经加载了 TikZ,因此额外的开销可以忽略不计,因此我已在主文档中添加了此包。但是,该包似乎在图形周围插入了额外的空间,如下所示:
\begin{annotate}
而没有使用包中的环境的图形callouts
给出:
使用环境时,为什么会出现这种稍微额外的水平空间和明显的垂直空间\begin{annotate}
,我该如何消除它呢?
该.sty
文件callouts
只有 93 行,但我无法弄清楚是什么导致了交互,我\renewenvironment
将环境定义添加%
到每行末尾,但没有效果。环境的定义\begin{annotate}
是(由作者 Markus Stuetz 提供):
\newenvironment{annotate}[2]%[num]%
{ \begin{tikzpicture}[scale=#2]% }%
% Annotate
\node (pic) at (0,0) {#1};%
\newdimen\xtic
\newdimen\ytic
\pgfextractx\xtic{\pgfpointanchor{pic}{east}}
\pgfmathparse{int(\xtic/1cm)}
\pgfmathsetmacro\xtic{\pgfmathresult}
\pgfextracty\ytic{\pgfpointanchor{pic}{north}}
\pgfmathparse{int(\ytic/1cm)}
\pgfmathsetmacro\ytic{\pgfmathresult}
}%
{ \end{tikzpicture} }
将内容放入annotate
环境中没有效果,使用如下方法:
\begin{annotate}{\includegraphics[width=\textwidth]{example-image-a}}{1}
\node[draw] at (0, 0) {\textbf{(a)}};
\end{annotate}
造成了相同的空间。
梅威瑟:
\documentclass{book}
\usepackage{callouts}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\captionsetup[figure]{position=bottom,labelfont={bf, small}, labelsep=period, textfont={small}, aboveskip=6pt, belowskip=-6pt, singlelinecheck=off, justification=justified}
\begin{document}
\begin{figure}[t]
\begin{annotate}{\includegraphics[width=\textwidth]{example-image-a}}{1}
\node[draw] at (0, 0) {\textbf{(a)}};
\end{annotate}
\caption{With annotate}
\end{figure}
\begin{figure}[t]
\includegraphics[width=\textwidth]{example-image-a}
\caption{Without annotate}
\end{figure}
\end{document}
编辑:根据@David Carlisle 的建议,我annotate
通过删除空格并将注册表定义移到环境之外来更改默认定义,如下所示:
\newdimen\xtic%
\newdimen\ytic%
\renewenvironment{annotate}[2]%
{\begin{tikzpicture}[scale=#2]%
\node (pic) at (0,0) {#1};%
\pgfextractx\xtic{\pgfpointanchor{pic}{east}}%
\pgfmathparse{int(\xtic/1cm)}%
\pgfmathsetmacro\xtic{\pgfmathresult}%
\pgfextracty\ytic{\pgfpointanchor{pic}{north}}%
\pgfmathparse{int(\ytic/1cm)}%
\pgfmathsetmacro\ytic{\pgfmathresult}%
}%
{\end{tikzpicture}}
但是它仍然会造成空间(顶部在annotate
环境内)。还有什么原因会导致空间?
答案1
作为对@JamesT 答案的补充,对annotate
环境重新定义进行了小范围的修改。这可能很有趣...
\documentclass[oneside]{book}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{callouts}
\captionsetup[figure]{position=bottom,
font=small, labelfont=bf, labelsep=period,
aboveskip=6pt, belowskip=-6pt,
singlelinecheck=off, justification=justified}
\newdimen\xtic
\newdimen\ytic
\renewenvironment{annotate}[3][inner sep=0pt]% <---
{\begin{tikzpicture}[scale=#3]
% Annotate
\node[#1] (pic) at (0,0) {#2};
\pgfextractx\xtic{\pgfpointanchor{pic}{east}}
\pgfmathparse{int(\xtic/1cm)}
\pgfmathsetmacro\xtic{\pgfmathresult}
\pgfextracty\ytic{\pgfpointanchor{pic}{north}}
\pgfmathparse{int(\ytic/1cm)}
\pgfmathsetmacro\ytic{\pgfmathresult}
}%
{\end{tikzpicture}}
\begin{document}
\begin{figure}[t]
\begin{annotate}{\includegraphics[width=\linewidth]{example-image-a}} % <---
{1}
\node[draw] at (-3.55, 2.95) {\textbf{(a)}};
\end{annotate}
\caption{With default annotate annotation settings}
\end{figure}
\begin{figure}[b]
\begin{annotate}[draw=cyan, line width=2mm,
text width=\dimexpr\textwidth-2mm,
inner sep=0pt] % <---
{\includegraphics[width=\linewidth]{example-image-a}} % <---
{1}
\node[draw] at (-3.55, 2.95) {\textbf{(a)}};
\end{annotate}
\caption{With optional settings of the annotate}
\end{figure}
\end{document}
(红线表示页面布局)
答案2
应用@David Carlisle 的评论并编辑以包含另一个参数,该参数包含传递给定义中包含的\renewenvironment{annotate}
选项,结果如下:\node
重要的选项是inner sep=0pt
,无论出于什么原因,这都会在使用图形时造成图形周围出现空格\textwidth
。
\documentclass[oneside]{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{callouts}
\captionsetup[figure]{position=bottom,labelfont={bf, small}, labelsep=period, textfont={small}, aboveskip=6pt, belowskip=-6pt, singlelinecheck=off, justification=justified}
\newdimen\xtic
\newdimen\ytic
\renewenvironment{annotate}[3]%[num]%
{\begin{tikzpicture}[scale=#2]% }%
% Annotate
\node[#3] (pic) at (0,0) {#1};%
\pgfextractx\xtic{\pgfpointanchor{pic}{east}}
\pgfmathparse{int(\xtic/1cm)}
\pgfmathsetmacro\xtic{\pgfmathresult}
\pgfextracty\ytic{\pgfpointanchor{pic}{north}}
\pgfmathparse{int(\ytic/1cm)}
\pgfmathsetmacro\ytic{\pgfmathresult}
}%
{\end{tikzpicture}}
\begin{document}
\begin{figure}[t]
\begin{annotate}{\includegraphics[width=\textwidth]{example-image-a}}{1}{inner sep=0pt,draw=none,fill=white}
\node[draw] at (-3.55, 2.95) {\textbf{(a)}};
\end{annotate}
\caption{With annotate}
\end{figure}
\begin{figure}[b]
\includegraphics[width=\textwidth]{example-image-a}
\caption{Without annotate}
\end{figure}
\end{document}
我将通过电子邮件联系作者,询问是否可以进行@David Carlisle 所做的更改(删除周围的多余空格{tikzpicture}
并将xtic
/ytic
移出定义)以及为\node (pic)
选项添加(可能是可选的)参数。