You need to enable JavaScript to run this app. 如何缩小Visual Studio Code中Jupyter输出内容的行间距
优惠活动
大模型
产品
解决方案
定价
更多

如何缩小Visual Studio Code中Jupyter输出内容的行间距

VSCode Jupyter 输出内容行间距调整方案

效果参考

  • 当前偏大的行间距效果:
    当前输出效果
  • 期望的和浏览器端Jupyter一致的紧凑效果:
    期望输出效果

调整方法

方法1:全局生效(所有Jupyter Notebook都适用)

  1. 打开VSCode设置:Windows/Linux按快捷键 Ctrl+,,Mac按快捷键 Cmd+,,也可以点击左下角齿轮图标选择「设置」
  2. 在设置搜索框输入 Jupyter: Custom CSS,找到对应配置项
  3. 在输入框中填入以下CSS代码,可自行调整line-height的数值,数值越小行间距越窄,1.2和浏览器端Jupyter默认行间距一致:
.output_area pre {
    line-height: 1.2 !important;
}
.jp-RenderedText pre {
    line-height: 1.2 !important;
}
  1. 保存设置后重启VSCode,或者右键当前Notebook标签页选择「重新加载网页」即可生效。

方法2:单Notebook生效(仅当前打开的Notebook适用)

在当前Notebook的首个代码Cell中运行以下代码即可:

from IPython.core.display import HTML
HTML("""
<style>
.output_area pre {
    line-height: 1.2 !important;
}
.jp-RenderedText pre {
    line-height: 1.2 !important;
}
</style>
""")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.08 23:09:02