我想将两张图片并排放置作为子图,旋转 90 度,这两张图片填满整个页面。
虽然从外观上看这可行,但我对 hyperref 包及其目标存在一些问题。
问题如下:
- hyperref 中的链接链接到页面底部,我希望它们链接到图片的左上角,这样我点击链接后就能看到图片,而不仅仅是页码。
- 我想让图形填满整个页面,如何确保浮动元素位于其自己的页面上但可以四处浮动?(我使用的
\xhsize
是浮动元素剩余的空间,我认为这不适合我的情况)。注意:此处的新页面仅用于演示。
代码
\documentclass{report}
\usepackage{tikz}
\usepackage[hyperindex, colorlinks]{hyperref}
\usepackage{caption}
\usepackage[list=on]{subcaption}
\usepackage[figuresright]{rotating} %rotated figures
\usepackage{floatrow} %subfigures
\usepackage{adjustbox}
\floatsetup{style=ruled,footposition=caption,capposition=bottom} %make graphics look like booktables
\floatsetup[subfigure]{style=plain}
\DeclareCaptionSubType[alph]{figure}
\captionsetup[subfigure]{labelformat=brace,justification=centerlast}
\begin{document}
\newpage
\begin{sidewaysfigure}[h!]
\centering
\ffigbox[\FBwidth]{
\begin{subfloatrow}
\ffigbox[.5\Xhsize]{\caption{variant a}\label{fig:a}}{\adjustbox{max width={.5\Xhsize}}{\begin{tikzpicture}\node {smaple};\end{tikzpicture}}}
\ffigbox[\Xhsize]{\caption{variant b}\label{fig:b}}{\adjustbox{max width={\Xhsize}}{\begin{tikzpicture}\node {smaple};\end{tikzpicture}}}
\end{subfloatrow}}
{\caption{flavours}\label{fig}}
\end{sidewaysfigure}
\newpage
\ref{fig} contains: \ref{fig:a} and \ref{fig:b}.
\newpage
\listoffigures
\end{document}
答案1
对于问题 (1),您可以使用hycap
包。因此,当您单击链接时,引用会跳转到图中,而不是底部。至于跳转到左上角,您可能需要进行一些调整,但如果您的目标是跳转到图中,只需添加:
\usepackage{hyperref}
\usepackage[figure, figure*]{hypcap}
如果添加该选项[all]
,它将对图形、表格和浮动版本以这种方式运行*
。
文档链接hypcap
:http://texdoc.net/texmf-dist/doc/latex/oberdiek/hypcap.pdf
\capstart
直接添加\begin{subfloatrow}
将使图形链接跳转到顶部而不是底部,因为底部什么都看不见。
\documentclass{report}
\usepackage{tikz}
\usepackage{caption}
\usepackage[list=on]{subcaption}
\usepackage[figuresright]{rotating} %rotated figures
\usepackage{floatrow} %subfigures
\usepackage{adjustbox}
\usepackage[hyperindex, colorlinks]{hyperref}
\usepackage[all]{hypcap}
\floatsetup{style=ruled,footposition=caption,capposition=bottom} %make graphics look like booktables
\floatsetup[subfigure]{style=plain}
\DeclareCaptionSubType[alph]{figure}
\captionsetup[subfigure]{labelformat=brace,justification=centerlast}
\begin{document}
\newpage
\begin{sidewaysfigure}[h!]
\centering
\ffigbox[\FBwidth]{
\begin{subfloatrow}
\capstart
\ffigbox[.5\Xhsize]{\caption{variant a}\label{fig:a}}{\adjustbox{max width={.5\Xhsize}}{\begin{tikzpicture}\node {smaple};\end{tikzpicture}}}
\ffigbox[\Xhsize]{\caption{variant b}\label{fig:b}}{\adjustbox{max width={\Xhsize}}{\begin{tikzpicture}\node {smaple};\end{tikzpicture}}}
\end{subfloatrow}}
{\caption{flavours}\label{fig}}
\end{sidewaysfigure}
\newpage
\ref{fig} contains: \ref{fig:a} and \ref{fig:b}.
\newpage
\listoffigures
\end{document}
答案2
扩展以允许宽度和高度不一致的图像。所有图像都缩放到相同的高度,并并排约束以适应用户定义的\rowfigurewidth
。
我并不是在解决链接问题,而是在解决对整页图表的要求。我采用了我在回答 ted 之前的问题时开发的“行图”方法(从环境中提取命令)。
作品的核心是在sidewaysfigure
环境中构建人物形象
\rowfigurewidth{
行图的约束宽度}
(“包”默认为\textwidth
)
\startrowfigure{
第一张图片,tikz,或者其他}
\addrowfigure{
第二张图片,tikz,或者其他}
...(可以向行中添加更多行图)
\finishrowfigure
然后,作为 的参数\ffigbox
,使用\scaledrowfigure{1}
和\scaledrowfigure{2}
代替原始(未缩放)图像。此外,作为 的可选参数\ffigbox
,使用[\rowfigwidth{1}]
和[\rowfigwidth{2}]
来指示该特定子图的宽度。
以下是完整代码:
\documentclass{report}
\usepackage{tikz}
\usepackage[hyperindex, colorlinks]{hyperref}
\usepackage{caption}
\usepackage[list=on]{subcaption}
\usepackage[figuresright]{rotating} %rotated figures
\usepackage{floatrow} %subfigures
\usepackage{adjustbox}
\usepackage{scalerel}
\usepackage{fp}
\usepackage{stackengine}
\def\stacktype{L}
\usepackage{xcolor}
\newcount\figfracwidthc
\newcount\figwidthc
\newcount\textwidthc
\newcounter{rowfigcount}
\newcounter{rowfigindex}
\newsavebox\compositefig
\newsavebox\subrowfig
\newlength\rowfigwd
\gdef\rowfigwdstring{\textwidth}
\newcommand\rowfigurewidth[1]{\edef\rowfigwdstring{#1}}
\newcommand\startrowfigure[2][0]{%
\sbox\compositefig{#2}%
\edef\rowfigstart{#1}%
\setcounter{rowfigcount}{#1}%
\addtocounter{rowfigcount}{1}%
\expandafter\def\csname rowfig\roman{rowfigcount}\endcsname{#2}%
}
\newcommand\addrowfigure[1]{%
\sbox\compositefig{\scalerel{\usebox{\compositefig}}{$#1$}}%
\addtocounter{rowfigcount}{1}%
\expandafter\def\csname rowfig\roman{rowfigcount}\endcsname{#1}%
}
\newcommand\finishrowfigure{%
\figwidthc=\wd\compositefig%
\setlength{\rowfigwd}{\rowfigwdstring}%
\textwidthc=\rowfigwd%
\FPdiv\scaleratio{\the\textwidthc}{\the\figwidthc}%
\global\edef\scaleratio{\scaleratio}%
\getrowfigwidths%
}
\newcommand\scaledrowfigure[1]{%
\scalebox{\scaleratio}{\scalerel*{%
$\csname rowfig\romannumeral #1\endcsname$}{%
$\csname rowfig\roman{rowfigcount}\endcsname$}}%
}
\newcommand\getrowfigwidths{%
\setcounter{rowfigindex}{\rowfigstart}%
\sbox{\compositefig}{}%
\whiledo{\value{rowfigindex} < \value{rowfigcount}}{%
\stepcounter{rowfigindex}%
\sbox{\subrowfig}{\scaledrowfigure{\arabic{rowfigindex}}}%
\sbox{\compositefig}{%
\usebox{\compositefig}\scaledrowfigure{\arabic{rowfigindex}}}%
\expandafter\xdef\csname rowfigwdARRAY\roman{rowfigindex}\endcsname{%
\the\wd\subrowfig}%
}%
}
\newcommand\rowfigwidth[1]{\csname rowfigwdARRAY\romannumeral #1\endcsname}
\floatsetup{style=ruled,footposition=caption,capposition=bottom} %make graphics look like booktables
\floatsetup[subfigure]{style=plain}
\DeclareCaptionSubType[alph]{figure}
\captionsetup[subfigure]{labelformat=brace,justification=centerlast}
\columnsep=0pt
\begin{document}
\newpage
\begin{sidewaysfigure}[h!]%
\gdef\figone{\fbox{\begin{tikzpicture}\node {\stackunder{Sample 1}{!!!}};\end{tikzpicture}}}%
\gdef\figtwo{\fbox{\begin{tikzpicture}\node {Sample 2xxxx};\end{tikzpicture}}}%
\gdef\figthree{\fbox{\begin{tikzpicture}\node {Sample 3};\end{tikzpicture}}}%
%%% UNCOMMENT NEXT THREE LINES TO TEST WITH RULES OF KNOWN SIZE
%\gdef\figone{\textcolor{red}{\rule{.5in}{1ex}}}%
%\gdef\figtwo{\rule{.3in}{1ex}}%
%\gdef\figthree{\textcolor{blue}{\rule{.2in}{1ex}}}%
\centering%
\ffigbox[\textheight]{%
\rowfigurewidth{\textheight}%
\startrowfigure{\figone}%
\addrowfigure{\figtwo}%
% UNCOMMENT TO TEST THREE BOXES
\addrowfigure{\figthree}%
\finishrowfigure%
\begin{subfloatrow}%
\ffigbox[\rowfigwidth{1}]{\caption{variant a\label{fig:a}}}%
{\scaledrowfigure{1}}%
\ffigbox[\rowfigwidth{2}]{\caption{variant b\label{fig:b}}}%
{\scaledrowfigure{2}}%
% UNCOMMENT NEXT TWO LINES TO TEST THREE BOXES
\ffigbox[\rowfigwidth{3}]{\caption{variant c\label{fig:c}}}%
{\scaledrowfigure{3}}%
\end{subfloatrow}}%
{\caption{flavours \the\textheight}\label{fig}}%
\end{sidewaysfigure}
\newpage
\ref{fig} contains: \ref{fig:a}, \ref{fig:b}
% UNCOMMENT NEXT LINE TO TEST THREE BOXES
, and \ref{fig:c}%
.
\newpage
\listoffigures
\newpage
Test to see if scaled rowfigures span textwidth
\startrowfigure{\figone}
\addrowfigure{\figtwo}
\addrowfigure{\figthree}
\finishrowfigure
\scaledrowfigure{1}%
\scaledrowfigure{2}%
\scaledrowfigure{3}
\rule{\textwidth}{.1ex}
They do.
These were the originals:
\figone\figtwo\figthree
\end{document}