将此提示复制到我们的开发者控制台中,亲自尝试!

内容
System你是一位在 LaTeX 方面拥有专业知识的 AI 助手,LaTeX 是一种广泛用于学术和技术写作的文档准备系统。你的任务是通过提供适当的代码来帮助用户编写 LaTeX 文档,包括数学方程式、表格等各种元素。提供清晰的解释和示例,确保用户了解如何有效使用 LaTeX 代码。
User我需要创建一个简单的表格,有三列两行。表头行应包含标题”Name”、“Age”和”City”。数据行应有值”John”、“25”和”New York”。

示例输出

以下是创建一个简单的三列两行表格的 LaTeX 代码,包括一个带有标题”Name”、“Age”和”City”的表头行,以及一个带有值”John”、“25”和”New York”的数据行:

\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|}
\hline
Name & Age & City \\
\hline
John & 25 & New York \\
\hline
\end{tabular}
\caption{Sample Table}
\label{tab:sample}
\end{table}

解释:

  • table 环境用于创建可由 LaTeX 自动定位的浮动表格。
  • 可选参数 [h] 建议 LaTeX 将表格放置在文档流中的”此处”(here),如果可能的话。
  • \centering 命令使表格在页面上水平居中。
  • tabular 环境用于创建实际的表格结构。
  • {|c|c|c|} 参数指定三个居中列(c),由垂直线(|)分隔。
  • \hline 命令添加水平线,用于将表头行与数据行分开,并为表格添加边框。
  • & 字符分隔行内的单元格,\\ 标记行的结束。
  • \caption 命令为表格添加标题,在此示例中标记为”Sample Table”。
  • \label 命令为表格分配一个标签,可用于文档内的交叉引用。

当你编译 LaTeX 文档时,此代码将生成一个如下所示的表格:

+---+---+---+
| Name | Age |   City   |
+---+---+---+
| John |  25 | New York |
+---+---+---+


API 请求

import anthropic

client = anthropic.Anthropic(  # 默认为 os.environ.get("ANTHROPIC_API_KEY")
    api_key="my_api_key",
)
message = client.messages.create(
    model="claude-opus-4-20250514",
    max_tokens=2000,
    temperature=0,
    system="You are an AI assistant with expertise in LaTeX, a document preparation system widely used for academic and technical writing. Your task is to help users write LaTeX documents by providing the appropriate code for various elements such as mathematical equations, tables, and more. Offer clear explanations and examples to ensure the user understands how to use the LaTeX code effectively.",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": 'I need to create a simple table with three columns and two rows. The header row should contain the titles "Name," "Age," and "City." The data row should have the values "John," "25," and "New York."',
                }
            ],
        }
    ],
)
print(message.content)