缩小图像,但在乳胶中不放大
我有一个包含 includegraphics 命令的命令 - 我可以将图像传递给我的命令,它会在实际包含图像之前为我执行一些标准格式设置。 我通过此命令包含的一些图像小于 \textwidth,而另一些则更大。 我想将较大的图像缩小到 \textwidth,而不放大较小的图像 - 这意味着我不能只是这样做
\includegraphics[width=\textwidth]{img}
有没有办法指定 maxwidth? 或者,我可以以某种方式获取图像的宽度,这样我就可以做类似的事情
\ifthenelse{\imagewidth > \textwidth}{%
\includegraphics[width=\textwidth]{img}}{%
\includegraphics{img}}
I have a command which includes an includegraphics command - I can pass an image to my command, and it will do some standard formatting for me before actually including the image. Some of the images that I'm including via this command are smaller than \textwidth, while some are larger. I'd like to scale the larger images down to \textwidth, while not scaling the smaller images up - this means I can't just do
\includegraphics[width=\textwidth]{img}
Is there a way to specify a maxwidth? Or, can I get the width of the image somehow so I can do something like
\ifthenelse{\imagewidth > \textwidth}{%
\includegraphics[width=\textwidth]{img}}{%
\includegraphics{img}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我喜欢一个附加参数来选择性地缩小或放大图像,所以我的 \scalegraphics 版本如下所示:
I like an additional parameter for optionally scaling the image down or up a bit, so my version of \scalegraphics looks like this:
要获取图像的宽度,您可以使用以下代码:
您可以在文档序言中使用此代码来创建一个新命令来自动设置宽度:
然后,在您的文档中:
我希望这会有所帮助!
To get the width of the image you can use this code:
You could use this in the document preamble to create a new command to automatically set the width:
and then, in your document:
I hope this helps!
adjustbox
包对于这。 下面您将找到一个简短的示例。 它允许执行以下操作(除了修剪、剪裁、添加边距和相对缩放之外):如果您使用
export
包选项,则其大部分键都可以直接与\includegraphics
一起使用。例如与您相关的键,最大宽度
。The
adjustbox
package is usefull for this. Below you will find a short example. It allows the following (besides triming, clipping, adding margins and relative scaling:If you use the
export
package option most of its keys can be used directly with\includegraphics
. FOr instance the key relevant to you,max width
.如果你想要约束的不是图像而是一个独立的
.tex
文件,你可以稍微修改 ChrisN 的\scalegraphics
,然后像这样使用它
当然, < code>adjustbox 按照 ted 的建议也可以工作:
If what you want to constrain is not an image but a standalone
.tex
file, you can slightly modify ChrisN's\scalegraphics
toand then use it like so
And of course,
adjustbox
as suggested by ted will work as well:经过几分钟的 CTAN 手册和 Google 结果搜索后,我想我可以有把握地说,你想做的事情要么是不可能的,要么是非常困难的。 我唯一的建议是您有两个命令,一个用于小图像,一个用于大图像,或者一个带有选项的命令。
可能有办法,但我将其留给其他 SO LaTeX 向导来提供更好的答案。
编辑:我错了,见上文。
After a few minutes of searching through CTAN manuals and Google results, I think I can safely say that what you want to do is either impossible or very hard. My only recommendation is that you have two commands, one for small images and one for large, or one command with an option.
There may be a way, but I leave it to other S.O. LaTeX wizards to provide a better answer.
Edit: I am wrong, see above.