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

内容
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 将表格放置在文档流中的”此处”(如果可能)。
  • \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-3-7-sonnet-20250219",
    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)