Как красиво разместить tikzpicture между абзацами?

Как красиво разместить tikzpicture между абзацами?

Я хочу красиво разместить свою tikzpicture между абзацами. Как мне это сделать? Я не хочу помещать ее в окружение картинки, потому что тогда под ней будет лишнее пространство.

\documentclass[11pt,a4paper,addpoints]{exam}
\unframedsolutions
%\printanswers
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{calc}

\newgeometry{left=2cm,top=2cm,right=2cm,bottom=2cm}

\begin{document}
\begin{questions}


Line above tikzpicture.

\begin{tikzpicture}[rounded corners=5mm]
\path node[rectangle,draw=green,fill=green!8,inner sep=.70cm] {\parbox{\textwidth-1.4cm-\fboxrule}{

\question[2] What is the first question?
\begin{solutionorlines}[4cm]
This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?
\end{solutionorlines}
}};
\end{tikzpicture}

Line under tikzpicture. I don't want this. I want the tikzpicture between paragraphs.

\end{questions}
\end{document}

введите описание изображения здесь

решение1

Рисование цветного блока — мой девиз для предложения tcolorboxрешения. Точный размер белого пространства можно задать с помощью before skipи after skip. Поскольку вы хотите, чтобы он был одинаковым, вы также можете использовать beforeafter skip. Я использую два блока ниже: первый — обычный, второй — просто для отображения настроек расстояния.

\documentclass[11pt,a4paper,addpoints]{exam}
\unframedsolutions
%\printanswers
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{calc}
\usepackage{tcolorbox}

\newgeometry{left=2cm,top=2cm,right=2cm,bottom=2cm}

\newtcolorbox{greenbox}[1][]{%
  size=fbox,
  arc=5mm,
  boxsep=0.7cm,
  %boxsep=\fboxsep,% uncommented to use \fboxsep
  colframe=green,
  colback=green!8,
  beforeafter skip=3mm,% <--- Space setting before and after
  #1%
}

\begin{document}

\begin{questions}

Line above tikzpicture.

\begin{greenbox}
  \question[2] What is the first question?
  \begin{solutionorlines}[4cm]
  This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?
  \end{solutionorlines}
\end{greenbox}

Line under tikzpicture. I don't want this. I want the tikzpicture between paragraphs.

Line above tikzpicture.

\begin{greenbox}[beforeafter skip=0mm]
  \question[2] What is the first question?
  \begin{solutionorlines}[4cm]
  This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?
  \end{solutionorlines}
\end{greenbox}

Line under tikzpicture. I don't want this. I want the tikzpicture between paragraphs.

\end{questions}

\end{document}

введите описание изображения здесь

решение2

Я не знаю examкласс, но, похоже questions, внутри среды все абзацы обрабатываются по-разному. Вы можете добавить новую строку, не добавляя разрыв абзаца.

\documentclass[11pt,a4paper,addpoints]{exam}
\unframedsolutions
%\printanswers
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{calc}

\newgeometry{left=2cm,top=2cm,right=2cm,bottom=2cm}

\begin{document}
\begin{questions}

Line above tikzpicture.\\[1em]
\begin{tikzpicture}[rounded corners=5mm]
\path node[rectangle,draw=green,fill=green!8,inner sep=.70cm] {
  \parbox{\textwidth-1.4cm-\fboxrule}{
    \question[2] What is the first question?
    \begin{solutionorlines}[4cm]
    This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?
    \end{solutionorlines}
  }};
\end{tikzpicture}\\[1em]
Line under tikzpicture. I don't want this. I want the tikzpicture between paragraphs.

\end{questions}
\end{document}

ПРИМЕЧАНИЕ:Вы можете проверить mdframedпакет, если хотите поместить вопросы в рамки.

введите описание изображения здесь

решение3

Это не полное решение, так как интервал немного не тот, а ширина ответа слишком большая. Нет времени на окончательные корректировки. Другие могут редактировать этот ответ или использовать его в качестве отправной точки:

\documentclass[11pt,a4paper,addpoints]{exam}
\unframedsolutions
\printanswers % or commented out for lines
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{calc}

\newgeometry{left=2cm,top=2cm,right=2cm,bottom=2cm}

\begin{document}
\begin{questions}

\question[2] What is the first question?
\begin{solutionorlines}[4cm]
\begin{minipage}[t][4cm]{\textwidth}This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?\end{minipage}
\end{solutionorlines}
\question[2] What is the second question?
\begin{solutionorlines}[4cm]
\begin{minipage}[t][4cm]{\textwidth} This box is smaller than when the solutions are not printed. How do I make this the same dimension as when answers are not printed?\end{minipage}
\end{solutionorlines}

\end{questions}
\end{document}

введите описание изображения здесь

введите описание изображения здесь

Связанный контент