我正在使用pgf 包缩放 .pgf 图像,但我不明白如何将图像缩放到与文本宽度完全相同。因此,标题似乎不在中心,因为它的中心位置参考的是文本中心,而不是图像中心。
这是一个 MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgf}
\begin{document}
\begin{figure}
\centering
\scalebox{0.5}{\input{test.pgf}}
\caption{Can you center me? Can you center me?Can you center me?}
\end{figure}
\end{document}
在使用这个包时,有没有办法将图像缩放到与文本宽度完全相同?或者有没有办法将标题置于图像中心而不是文本中心?
用于测试的简单 pgf 文件可能是这样的:
\begingroup%
\makeatletter%
\begin{pgfpicture}%
\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{12.162500in}{9.737500in}}%
\pgfusepath{use as bounding box, clip}%
\begin{pgfscope}%
\pgfsetbuttcap%
\pgfsetmiterjoin%
\definecolor{currentfill}{rgb}{0.300000,0.300000,0.300000}%
\pgfsetfillcolor{currentfill}%
\pgfsetfillopacity{0.500000}%
\pgfsetlinewidth{1.003750pt}%
\definecolor{currentstroke}{rgb}{0.300000,0.300000,0.300000}%
\pgfsetstrokecolor{currentstroke}%
\pgfsetstrokeopacity{0.500000}%
\pgfsetdash{}{0pt}%
\pgfpathmoveto{\pgfqpoint{0.242710in}{0.201968in}}%
\pgfpathlineto{\pgfqpoint{11.948671in}{0.201968in}}%
\pgfpathquadraticcurveto{\pgfqpoint{11.976437in}{0.201968in}}{\pgfqpoint{11.976437in}{0.229735in}}%
\pgfpathlineto{\pgfqpoint{11.976437in}{0.844102in}}%
\pgfpathquadraticcurveto{\pgfqpoint{11.976437in}{0.871868in}}{\pgfqpoint{11.948671in}{0.871868in}}%
\pgfpathlineto{\pgfqpoint{0.242710in}{0.871868in}}%
\pgfpathquadraticcurveto{\pgfqpoint{0.214944in}{0.871868in}}{\pgfqpoint{0.214944in}{0.844102in}}%
\pgfpathlineto{\pgfqpoint{0.214944in}{0.229735in}}%
\pgfpathquadraticcurveto{\pgfqpoint{0.214944in}{0.201968in}}{\pgfqpoint{0.242710in}{0.201968in}}%
\pgfpathclose%
\pgfusepath{stroke}%
\end{pgfscope}%
\end{pgfpicture}%
\makeatother%
\endgroup%
答案1
您可以使用 将某些内容缩放到文本宽度\resizebox
。或者,如果您的图像大于文本宽度,您可以使用 将其伸出两个边距\makebox
:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\makebox[\textwidth]{\scalebox{1.8}{\rule{10cm}{1cm}}}
\resizebox{\textwidth}{!}{{\rule{10cm}{1cm}}}
\caption{Can you center me? Can you center me?Can you center me?}
\end{figure}
\end{document}
答案2
\scalebox
由 定义,graphics
而不是 由 定义pgf
。
如果你想要一个物体变宽\textwidth
,那么
\scalebox{0.5}{...}
除非原始文本宽度正好是其两倍,否则将不起作用。
使用
\resizebox{\textwidth}{!}{...}