將此提示複製到我們的開發者主控台親自試試看!

內容
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)