如何将文字放在图片旁边

如何将文字放在图片旁边

我有这个:

\begin{figure}[!hb]
 \label{curve}
    \includegraphics[width=10cm, height=4cm]{images/smoothSinCurve.png}
\end{figure}

\begin{trivlist}  
\item \textcolor{orange}{Orange} is overdose
\item \textcolor{green}{Green} is underdose
\item \textcolor{blue}{Blue} is perfect dosage.
\end{trivlist}

它看起来像这样:

enter image description here

我怎样才能把它们放在同一条线上?

答案1

也许是这样的?

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{graphicx,xcolor}
\begin{document}    
\begin{figure}[!hb]
\centering
 \label{curve}
    \includegraphics[width=10cm, height=4cm]{example-image}
\begin{minipage}[b]{1.4in}
\begin{trivlist}  
\item \textcolor{orange}{Orange} is overdose
\item \textcolor{green}{Green} is underdose
\item \textcolor{blue}{Blue} is perfect dosage.
\end{trivlist}
\end{minipage}
\end{figure}

\end{document}

enter image description here

答案2

我写了一个命令,可以简单地做到这一点。它被@egreg更正,他在这里将其作为环境编写:https://tex.stackexchange.com/a/403618/138900

此后,我对它进行了修改,使其可以放置或不放置垂直分隔线:

\newlength\colG\newlength\colD%
\newenvironment{Compo}[1][0.5]
 {%
  \setlength{\colG}{#1\linewidth}%
  \setlength{\colD}{\linewidth}%
  \addtolength{\colD}{-\colG}%
  \addtolength{\colG}{-10pt}%
  \addtolength{\colD}{-10pt}%
  \par\noindent%
  \begin{minipage}{\colG}%
 }%
 {%
  \end{minipage}%
  \par%
 }%
\newcommand{\compobreak}{%
  \end{minipage}\hfill\vrule\hfill%
  \begin{minipage}{\colD}%
}%
\newcommand{\componubreak}{%
  \end{minipage}\hfill%
  \begin{minipage}{\colD}%
}%

由此可得:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{graphicx,xcolor}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% nouvel environnement Compo
\newlength\colG%\newlength\colD%
\newenvironment{Compo}[1][0.5]
 {%
  \setlength{\colG}{#1\linewidth}%
  \setlength{\colD}{\linewidth}%
  \addtolength{\colD}{-\colG}%
  \addtolength{\colG}{-10pt}%
  \addtolength{\colD}{-10pt}%
  \par\noindent%
  \begin{minipage}{\colG}%
 }%
 {%
  \end{minipage}%
  \par%
 }%
\newcommand{\compobreak}{%
  \end{minipage}\hfill\vrule\hfill%
  \begin{minipage}{\colD}%
}%
\newcommand{\componubreak}{%
  \end{minipage}\hfill%
  \begin{minipage}{\colD}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}   
\begin{Compo} [.5]
 \label{curve}
    \includegraphics[width=10cm, height=4cm]{example-image}
\compobreak

\begin{trivlist}  
\item \textcolor{orange}{Orange} is overdose
\item \textcolor{green}{Green} is underdose
\item \textcolor{blue}{Blue} is perfect dosage.
\end{trivlist}
\end{Compo}
\end{document}

输出:

enter image description here

相关内容