过去几天我在 Google 上进行了广泛的搜索,但没有找到解决这个问题的方法:
我有一个文档,其中包含图片和表格的侧边标题。当图片的宽度设置为 \textwidth 时,它看起来很棒。
但是,当我将其宽度改为较小时,标题会随图片一起向页面中心移动。因此,图像应水平居中于文本中,而侧标题应保留在文本旁边的空白处。
当我尝试将图像居中时,出现错误。如果有人知道解决方案就太好了。
这是我的代码:
\documentclass[10pt,twoside,a4paper,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
% Page layout_____________________________________________________________________
\usepackage[twoside]{geometry}
\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=130mm,marginparsep=8.2mm,marginparwidth=33mm,textheight=54\baselineskip,headheight=\baselineskip}
% Graphics________________________________________________________________________
\usepackage{graphicx}
% Captions at the side of the page
\usepackage[wide]{sidecap}
\usepackage[font=footnotesize,format=plain,labelfont={bf,sf},textfont={it},width=10pt]{caption}
% Begin document__________________________________________________________________
\begin{document}
\chapter{This Chapter}
\blindtext
\begin{SCfigure}[\sidecaptionrelwidth][h!]
\includegraphics[width=0.7\textwidth]{img/avalanche_triangle.png}
\caption{Avalanche Triangle after xy. This shows blablabla add some more information here.}
\label{avalanche}
\end{SCfigure}
\blindtext
\begin{SCfigure}[\sidecaptionrelwidth][h!]
%\begin{center} % This throws an error!
\includegraphics[width=\textwidth]{img/avalanche_triangle.png}
\caption{Avalanche Triangle after xy. This shows blablabla add some more information here.}
\label{avalanche}
%\end{center}
\end{SCfigure}
\blindtext
\end{document}
非常感谢你的帮助!
答案1
您可以使用 parbox 来获得所需的结果:
\documentclass[10pt,twoside,a4paper,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
% Page layout_____________________________________________________________________
\usepackage[twoside]{geometry}
\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=130mm,marginparsep=8.2mm,marginparwidth=33mm,textheight=54\baselineskip,headheight=\baselineskip}
% Graphics________________________________________________________________________
\usepackage{graphicx}
% Captions at the side of the page
\usepackage[wide]{sidecap}
\usepackage[font=footnotesize,format=plain,labelfont={bf,sf},textfont={it},width=10pt]{caption}
% Begin document__________________________________________________________________
\begin{document}
\chapter{This Chapter}
\blindtext
\begin{SCfigure}[\sidecaptionrelwidth][ht!]
\parbox{\textwidth}{\centering\includegraphics[width=0.7\textwidth]{example-image-a}}
\caption{Avalanche Triangle after xy. This shows blablabla add some more information here.}
\label{avalanche}
\end{SCfigure}
\blindtext
\begin{SCfigure}[\sidecaptionrelwidth][ht!]
%\begin{center} % This throws an error!
\includegraphics[width=\textwidth]{example-image-a}
\caption{Avalanche Triangle after xy. This shows blablabla add some more information here.}
\label{avalanche2}
%\end{center}
\end{SCfigure}
\blindtext
\end{document}
输出: