在解決方案環境中繪製草圖

在解決方案環境中繪製草圖

我希望在解決方案環境中繪製一組草圖,但我的嘗試導致以下錯誤訊息:

LaTeX Error: Float(s) lost.

我該如何解決?這是我的程式碼片段

  \documentclass[a4paper,11pt]{exam} % A4 paper and 11pt font size 

 \usepackage[english]{babel} % English language 
  \usepackage{tikz} % Tikz package for sketching 
  \usepackage{amsmath,amsfonts,amsthm,amssymb} %% American Mathematical Society packages

  \newcommand{\x}{\mathbf{x}}

\begin{document}

\begin{question}
 \question Let $\mathbf 0 = (0,0)$. Sketch the set $\{\x \in \mathbb R^2 d_m(\mathbf 0, x )\le 1\} $.
\begin{solution}
 \begin{figure}
 \centering
  \begin{tikzpicture} [scale =3]
  \draw[thick, ->] (-1.5,0) -- (1.5,0);
  \draw[thick, ->] (0,-1.5) -- (0,1.5)
  \draw (-1,-1) rectangle (1,1);
  \end{tikzpicture}
 \caption*{$d_m(\mathbb 0, \x) \le 1$
\end{figure}
\end{solution}
\end{questions}

答案1

你想要的不是一個figure環境,​​而是一個minipage

\documentclass[a4paper,11pt]{exam} % A4 paper and 11pt font size 

\usepackage[english]{babel} % English language 
\usepackage{tikz} % Tikz package for sketching 
\usepackage{amsmath,amsfonts,amsthm,amssymb} %% American Mathematical Society packages

\newcommand{\x}{\mathbf{x}}

\printanswers

\begin{document}

\begin{questions}
\question 
  Let $\mathbf{0} = (0,0)$. Sketch the set 
  $\{\x \in \mathbb{R}^2 : d_m(\mathbf{0}, \x)\le 1\}$.

\begin{solution}

\begin{minipage}{\linewidth}
\centering
  \begin{tikzpicture} [scale =3]
  \draw[thick, ->] (-1.5,0) -- (1.5,0);
  \draw[thick, ->] (0,-1.5) -- (0,1.5);
  \draw (-1,-1) rectangle (1,1);
  \end{tikzpicture}
\end{minipage}
\end{solution}
\end{questions}

\end{document}

在此輸入影像描述

訓練自己打字\mathbf{0}之類的,你會更快樂。

相關內容