← Back to Skills Marketplace
bg1avd

Latex Verbatim Center

by Rao Lin · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
101
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install latex-verbatim-center
Description
Redefines LaTeX verbatim to wrap with varwidth and center environments for proper horizontal centering of code blocks and ASCII art.
README (SKILL.md)

LaTeX Verbatim 居中技能

技能说明

技能名称:latex-verbatim-center
适用场景:当 LaTeX 文档中的 verbatim 环境(代码块、ASCII 图表等)无法正确居中时使用
技能标签:#LaTeX #排版 #居中 #verbatim #varwidth

问题描述

在 LaTeX 中,当尝试将 verbatim 环境放在 center 环境中时,内容往往不会真正居中,而是偏左对齐。这是因为 verbatim 环境会忽略外部的 \centering 指令。

典型症状

  • 第 3 页的 ASCII 图表偏左
  • 代码块没有居中显示
  • 使用 center 环境包裹 verbatim 无效

解决方案

核心方法

使用 varwidth 包包裹 verbatim 环境,再用 center 环境实现真正居中。

实现步骤

1. 添加宏包

在文档 preamble 中添加:

\usepackage{varwidth}

2. 重新定义 verbatim 环境

\let\originalverbatim\verbatim
\let\endoriginalverbatim\endverbatim

\renewenvironment{verbatim}{%
  \par
  \begin{center}
  \begin{varwidth}{\linewidth}
  \originalverbatim
  \footnotesize
}{%
  \endoriginalverbatim
  \end{varwidth}
  \end{center}
  \par
}

3. 完整示例

\documentclass{article}
\usepackage{fontspec}
\usepackage{xeCJK}
\usepackage{varwidth}  % 关键宏包

\setCJKmainfont{WenQuanYi Zen Hei}

% 重新定义 verbatim
\let\originalverbatim\verbatim
\let\endoriginalverbatim\endverbatim

\renewenvironment{verbatim}{%
  \par
  \begin{center}
  \begin{varwidth}{\linewidth}
  \originalverbatim
  \footnotesize
}{%
  \endoriginalverbatim
  \end{varwidth}
  \end{center}
  \par
}

\begin{document}
这里是正常文本。

\begin{verbatim}
def main():
    print("Hello World")
\end{verbatim}

这里也是正常文本。
\end{document}

技术原理

  • varwidth 环境会根据内容自动调整宽度(最大不超过 \linewidth
  • center 环境会将 varwidth 盒子居中
  • 组合使用实现真正的居中效果

替代方案对比

方法 效果 推荐度
center + varwidth ✅ 完美居中 ⭐⭐⭐⭐⭐
center + minipage ❌ 仍然偏左 ⭐⭐
xleftmargin=0.5\linewidth ❌ 会偏右
lrbox + center ⚠️ 有时有效 ⭐⭐⭐

注意事项

  1. 必须使用 varwidth 包,标准 minipage 无效
  2. 需要编译两次才能看到最终效果
  3. 如果文档中有多个 verbatim,只需重定义一次
  4. fancyvrb 包可能冲突,建议二选一

文员专用说明

适用人员:文档排版文员、技术文档编辑
使用频率:当发现文档中代码块或 ASCII 图表未居中时使用
操作步骤

  1. 检查文档是否已加载 varwidth
  2. 检查是否已重定义 verbatim 环境
  3. 如未配置,按上述步骤添加
  4. 编译两次 PDF 查看效果

相关文件

  • 技能位置:~/.openclaw/extensions/openclaw-latex-skills/skills/latex-verbatim-center/SKILL.md
  • 示例文档:/home/raolin/.openclaw/workspace-editor/PIM-SSMoE_Research_Report.tex
  • 最终版本:fixed42.pdf(使用此方案的第一个成功版本)

版本历史

  • v1.0 (2026-04-03): 初始版本,基于 fixed42.pdf 成功经验
  • 问题解决者:AI Assistant
  • 问题报告者:用户

参考资料

  • TeX Stack Exchange: "How to center verbatim" (2013)
  • LaTeX.org Forum: "center a text in verbatim" (2009)
  • CTAN: varwidth package documentation
  • TeX Live 2024 验证通过
Usage Guidance
This is a small, coherent LaTeX how-to that appears safe to use. Before applying it: (1) Prefer copying the provided redefinition into a test document first (or create a new environment like centerverbatim) rather than blindly changing global verbatim behavior in production documents. (2) Confirm you have varwidth installed (tlmgr install varwidth) and use modern TeX Live. (3) Be aware that compiling LaTeX with --shell-escape enables arbitrary code execution from packages; compile without shell-escape unless you trust the document and packages. (4) If you already use fancyvrb or other verbatim packages, test for conflicts. (5) Treat the example file paths in the docs as illustrative — ensure the skill does not run any automated edits against your home/workspace unless you explicitly invoke such actions.
Capability Analysis
Type: OpenClaw Skill Name: latex-verbatim-center Version: 1.0.0 The skill bundle provides a legitimate LaTeX typesetting solution for centering verbatim environments using the 'varwidth' package. The included files (SKILL.md, README.md, skill.json) contain standard LaTeX code snippets and routine shell commands for document compilation (xelatex) and package management (tlmgr). There is no evidence of malicious intent, data exfiltration, or harmful prompt injection.
Capability Assessment
Purpose & Capability
Name/description match the content: the SKILL.md explains a LaTeX technique (use varwidth + center and a redefinition of verbatim). Required TeX packages and suggested commands (tlmgr, xelatex) are appropriate for this task.
Instruction Scope
Instructions stay within LaTeX editing/compilation scope (add \usepackage{varwidth}, redefine environment, compile twice). The document includes example local file paths (e.g., ~/.openclaw/... and /home/raolin/...), which appear to be illustrative metadata rather than active instructions to read those files, but you should verify these references are generic examples and not pointers to sensitive files in your environment.
Install Mechanism
No install spec and no code files; minimal risk. The only recommended actions are using tlmgr to install the varwidth package if missing and running xelatex — conventional for LaTeX workflows.
Credentials
The skill declares no environment variables, credentials, or config paths. The listed TeX package requirements (varwidth, needspace) are proportionate to a LaTeX formatting solution.
Persistence & Privilege
always=false and the skill is user-invocable. It does not request permanent privileges or to modify other skills or system-wide settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install latex-verbatim-center
  3. After installation, invoke the skill by name or use /latex-verbatim-center
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
LaTeX Verbatim 居中技能 v1.0.0 - 首个发布版本,提供在 LaTeX 中 verbatim 环境(代码块/ASCII 图表)真正居中的完整方案 - 详细说明 `varwidth` 包和环境重定义的实现步骤及范例 - 包含不同方法对比、注意事项和常见问题说明 - 针对文档编辑人员提供操作指引和排查流程 - 附带示例文件位置及文档历史记录
Metadata
Slug latex-verbatim-center
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Latex Verbatim Center?

Redefines LaTeX verbatim to wrap with varwidth and center environments for proper horizontal centering of code blocks and ASCII art. It is an AI Agent Skill for Claude Code / OpenClaw, with 101 downloads so far.

How do I install Latex Verbatim Center?

Run "/install latex-verbatim-center" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Latex Verbatim Center free?

Yes, Latex Verbatim Center is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Latex Verbatim Center support?

Latex Verbatim Center is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Latex Verbatim Center?

It is built and maintained by Rao Lin (@bg1avd); the current version is v1.0.0.

💬 Comments