防止图像自动居中?

防止图像自动居中?

我正在插入像这样的图像......

\begin{figure}[h!]
  \includegraphics[width=400mm]{wut.png}
    \caption{Gantt Chart}
\end{figure}

但是,图像会自动从页面中央开始,由于其大小,图像会超出页面的右侧。我该如何强制让该图像从左侧边缘开始?

答案1

图像未居中;对于您想要插入的文本区域来说,它太大了。我使用的一种技巧是将pull其移到边缘。但是,如果您使用的是双面纸,则需要注意奇数页或偶数页。

在此处输入图片描述

本质上,您要做的就是hspace{<length>}在 前面添加一个\includegraphics。在下面的最小值中,我计算了它(参见\imagehskip)并在纸张边缘留出一点出血。由于您希望它“在此处”打印,因此您最好摆脱浮动并添加带有标题图像的标题(因为它可能也需要调整)。拉动量取决于图像的宽度和您使用的类。只需进行一些实验即可。

对于非常宽的图像(您需要一个中心插页),即图像需要分布在两页上。

在此处输入图片描述

这些就容易多了(如果它们占据了整个页面的高度)。

% First page
\includegraphics[height=0.95\textheight]{./graphics/africamedics}
% second page
\hspace*{-\textwidth} \includegraphics[height=0.95\textheight]{./graphics/africamedics}

这是一个相当长的极简

\documentclass[twoside]{book}
\usepackage[latin,english]{babel}
\usepackage{graphicx,lipsum,lettrine,xcolor,rotating}
\usepackage{multicol,caption}
\RequirePackage[showframe=false]{geometry}
\IfFileExists{changepage.sty}{\RequirePackage{changepage}}{}
\makeatletter
%% redefine LaTeX's plain as myplain for headings
\def\ps@myplain{\let\@mkboth\@gobbletwo
 \let\@oddhead\@empty\def\@oddfoot{\reset@font\hfil\thepage}
 \let\@evenhead\@empty\def\@evenfoot{\reset@font\thepage\hfil}}
%

%% Watermark package with small footprint
%% for more sophisticated macros use TikZ
 \def\even@samplepage{%
 \begin{picture}(0,0)
   \put(\Xeven,\Yeven){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
\end{picture}
}
%% Define a macro to print SAMPLE PAGE IN THE MARGIN
\def\odd@samplepage{%
 \begin{picture}(0,0)
   \put(\Xodd,\Yodd){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
 \end{picture}
}
%% Define the watermark words
\def\watermarktext#1{\gdef\watermark@text{\fontfamily{phv}\selectfont#1}}
\def\watermarktextcolor#1{\gdef\watermark@textcolor{#1}}
\watermarktext{PRE-PRINT}
\watermarktextcolor{purple}

%% redefine LaTeX's plain as myplain for headings
\def\ps@samplepage{\let\@mkboth\@gobbletwo
 \let\@oddhead\odd@samplepage\def\@oddfoot{\reset@font\hfil\thepage}
 \let\@evenhead\even@samplepage\def\@evenfoot{\reset@font\thepage\hfil}}
%%
%
%% We define two macros to position the watermark on the page
\def\Xodd{500}
\def\Xeven{-70}\def\Yeven{-810}
\def\Yeven{-\expandafter\strip@pt\textheight}
\let\Yodd\Yeven

\newlength\bleed@clearance
\setlength\bleed@clearance{0mm}
%% image corrections
%\the\dimexpr
%1in+\marginparwidth+\textwidth+\marginparsep+\evensidemargin-0.8in\relax
\newlength\oddcorrection
%\setlength\oddcorrection{\dimexpr(-1in-\oddsidemargin)+\bleed@clearance\relax}
\setlength\oddcorrection{\dimexpr(-1in+\oddsidemargin-\marginparsep+7pt)+\bleed@clearance\relax}

\newlength\evencorrection
\setlength\evencorrection{\dimexpr(-\marginparwidth-\marginparsep-\oddsidemargin-1pt)\relax}
%% caption related
\newlength\captiontextwidth
\setlength\captiontextwidth{\dimexpr 0.7\paperwidth\relax}
%% caption corrections
%\newlength\oddclearance
%\setlength\oddclearance{\dimexpr 7cm\relax}
%\newlength\evenclearance
%\setlength\evenclearance\bleed@clearance
%
%  we set two macros to cater for recto and verso
%  pages
%  \imagehskip is the shift of the image
%  we use changepage tofind out
%  if we recto or verso
\def\imagehskip{%
 \checkoddpage%
 \if@twoside% 
 \ifoddpage%
  \noindent\hspace*{\oddcorrection}%
\else%
  \hspace*{\evencorrection}%
\fi%
\else
   \noindent\hspace*{\oddcorrection}%
\fi
}%
% similarly define the captionskip amount. This also will
% depend on the paper setout as well as the page being
% recto or verso.
\def\captionhskip{%
\checkoddpage
\if@twoside%
 \ifoddpage%
%% Need to define a small margin at the end, if bleed is zero is a problem 50pt
  \hspace*{\dimexpr \oddcorrection-\bleed@clearance+0.3\paperwidth-50pt\relax}%
   \else%
   \hspace*{\dimexpr-1in-\oddsidemargin-\marginparsep\relax}%
 \fi%
 \else%
  \hspace*{\dimexpr 0.25\paperwidth+\oddcorrection-\bleed@clearance\relax}%
 \fi%
}%
%%
%% we check for odd and even numbers with the changepage package.
%% we first check if the page is odd.
%
%% Include the graphic
%% The image needs to be the sixe of the paper - clearance
\def\addimage#1{%
\checkoddpage%
%% The image width is determined by the paper width - bleed clearance
\imagehskip\includegraphics[width=\dimexpr\paperwidth-\bleed@clearance\relax]{./graphics/#1}%
\par%
\vspace{0.5\baselineskip}%
}% do a vsplit here 
%
\newcommand\addcaption[2][A heading]{%
   \captionhskip
   \vbox\bgroup
    \hsize\captiontextwidth
    \parindent0pt\textbf{#1}\quad#2\par
    \egroup
    %\vfill\vfill
}%
%% The multicol caption, displays its caption as multicolumns
%%  it uses the package multicol with a default setting of 3 columns
%% 
\newcommand\addmulticolcaption[2][3]{%
\begin{multicols}{#1}
#2
\end{multicols}
\par
 } %
%

\pagestyle{samplepage}
\begin{document}
\newgeometry{top=5mm,bottom=15mm}
.
\newpage
%% First page
\thispagestyle{samplepage}
\clearpage
\addimage{botticelli02}\par
\addcaption{\protect\lipsum[1]}\par
\bigskip
\lettrine{M}{adonna}\lipsum*[3]
\par


\clearpage
%% First page
\clearpage
\addimage{botticelli02}\par
\addcaption{\protect\lipsum[1]}\par
\bigskip
\lettrine{M}{adonna}\lipsum*[3-4]
\par
\clearpage
%% First page
\addimage{botticelli16}
\addcaption{\protect\lipsum*[3]}

\restoregeometry
\end{document}

答案2

正如 egreg 所评论的那样,figure环境确实不是默认居中。如果缩小尺寸,您会看到图形左对齐,正好位于页面左边距的开始位置。该[showframe]选项与包一起使用,geometry以显示页面边距的位置:

在此处输入图片描述

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[h!]
  \includegraphics[width=100mm]{wut.png}
    \caption{Gantt Chart}
\end{figure}
\end{document}​

答案3

(这基本上与https://tex.stackexchange.com/a/16584/4012https://tex.stackexchange.com/a/39148/4012

这是一个适用于 410mm 纸张宽度的解决方案,假设您不想缩放图片,正如您的问题所暗示的那样。如果您愿意缩放图片(如果您手边没有 410mm 的纸张,这可能是必要的),请删除 行geometry并嵌入图片(例如 )\includegraphics[width=0.9\paperwidth]{wut.png},这样看起来可能不错。

请注意,本例中图片居中。如果要让图片从页面左边框开始,则需要不同的代码,但最好知道我们使用的纸张、图片的宽度等。不过,此解决方案可能适合您。

\documentclass{article}

\usepackage[demo]{graphicx}% demo because I don't have your file.

\usepackage[paperwidth=410mm,showframe]{geometry}
                  % showframe to show where normal text would end

\begin{document}
\begin{figure}[h!]
  \makebox[\textwidth][c]{\includegraphics[width=400mm]{wut.png}}
    \caption{Gantt Chart}
\end{figure}
\end{document}

相关内容