You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Quarto文档中旋转PNG格式图片?

Quarto Article格式下旋转图片的可行方案

针对不同输出格式(HTML/PDF),可以用以下方法实现图片横向旋转:

1. HTML输出:自定义CSS样式

给目标图片添加自定义类,通过CSS实现旋转:

  • 在文档开头的YAML配置中引入自定义CSS文件:
format:
  html:
    css: custom.css
  • 在custom.css中添加旋转样式:
.rotate-90 {
  transform: rotate(90deg);
  transform-origin: center;
  /* 调整边距避免布局溢出 */
  margin: 3em 0;
}
  • 插入图片时指定类名:
    ![图片描述](your-image.png){.rotate-90}

2. PDF输出:LaTeX命令直接控制

Quarto PDF基于LaTeX编译,可直接用\rotatebox命令插入旋转后的图片:

\rotatebox{90}{\includegraphics[width=\textheight]{your-image.png}}

width=\textheight是让旋转后的图片高度适配页面宽度,可根据实际需求调整为0.9\textheight这类值。

3. 代码生成的图片:直接调整画布方向

如果图片是通过代码(R/Python等)生成的,可在绘图阶段直接设置横向画布:

Python(Matplotlib示例)

import matplotlib.pyplot as plt
# 绘制内容
plt.bar(["A", "B", "C"], [10, 20, 15])
# 设置横向画布尺寸
plt.gcf().set_size_inches(12, 6)
plt.savefig("horizontal-plot.png")

R(ggplot2示例)

library(ggplot2)
p <- ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point()
# 保存时设置横向尺寸
ggsave("horizontal-plot.png", p, width=12, height=6)

内容的提问来源于stack exchange,提问作者kwalz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 03:30:54