添加 tikz 箭头后对侧边标题进行水平调整

添加 tikz 箭头后对侧边标题进行水平调整

我有一个带侧边标题的图,我在图片上添加了一个箭头,但现在自从我添加了箭头后,所有内容都不再居中了,有没有办法强制居中以适应我使用 tikz 添加的箭头?谢谢您的宝贵时间。

输出

\documentclass[a4paper, twoside, 12pt]{report}
\usepackage[a4paper,showframe,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds}

\begin{document}
\begin{figure}[h!]
\begin{tikzpicture}
\useasboundingbox (0,0);
    \node[single arrow,draw=black,fill=black,minimum height=4.8cm, rotate=270] at (3.8,-2.8) {};
\end{tikzpicture}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=4cm}}]{figure}[\FBwidth]{\caption{caption here}}{\includegraphics[scale=0.32]{SizeExChrom}}

\end{figure}
\end{document}

答案1

当前代码的问题在于,由于您使用了\useasboundingbox (0,0);

为了更好地控制箭头的定位,我建议您将图像也包含在内\nodetikzpicture保留自然边界框,这样居中时就会考虑适当的宽度。另一个优点是,现在,借助库calc,您可以让 TikZ 计算箭头的高度:

在此处输入图片描述

代码:

\documentclass[a4paper, twoside, 12pt]{report}
\usepackage[a4paper,showframe,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,calc}

\begin{document}
\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=4cm}}]{figure}[\FBwidth]{\caption{caption here}}{%
\begin{tikzpicture}
\node[anchor=south east,inner sep=0pt] (image)
  {\includegraphics[width=6cm,height=7cm]{example-image-a}};
\path
  let
  \p1=(image.north),
  \p2=(image.south)
  in
  node[
    single arrow,
    draw=black,
    fill=black,
    minimum height=\y1-\y2,
    rotate=270
    ] 
    at ([shift={(20pt,0pt)}]image.east) {};
\end{tikzpicture}%
}
\end{figure}
\end{document}

附注:不要使用[!h]浮点位置说明符,因为它的限制性太强,很容易导致灾难;要么使用限制性较小的说明符,要么根本不使用。

答案2

这是您想要实现的吗(或多或少)?

浮动框

\documentclass[a4paper, twoside, 12pt]{report}
\usepackage[a4paper,showframe,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds}

\begin{document}
\begin{figure}[h!]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=4cm}}]{figure}[\FBwidth]{\caption{caption here}}%
{\includegraphics[height=4.8cm]{example-image}\begin{tikzpicture}
%\useasboundingbox (0,0);
    \node[single arrow,draw=black,fill=black,minimum height=4.8cm, rotate=270] at (3.8,-2.8) {};
\end{tikzpicture}}

\end{figure}
\end{document}

相关内容