我正在尝试在 itemize 中插入图片。但我想在图片的侧面添加一些文字

我正在尝试在 itemize 中插入图片。但我想在图片的侧面添加一些文字

代码部分为:

\begin{itemize}
\item....
\begin{minipage}[t]{0.7\textwidth}
\includegraphics[width=0.7\textwidth]{Pic/Ciclo cardiaco.png}
\end{minipage}
\item.....
\end{itemize}

我需要侧面的文字。

在此处输入图片描述

答案1

该解决方案用于tikz放置侧面文字。

(您不需要理解 tikz 代码)

该命令\InsertImageText{<image name>}{<side text>}将图像和文本放在其右侧。

您可以设置图像的宽度和文本的宽度、字体以及相对于图像右侧中心的 xy 位置。

C

\documentclass{article}

\usepackage{graphicx}

\usepackage{kantlipsum} % ONLY for dummy text   

%**************************************** added 
\usepackage{tikz}
\newlength{\imageheight}
\newlength{\imagewidth}
\newlength{\TextWidth}
\newlength{\TextXshift}
\newlength{\TextYshift}
% define the parameters  here <<<<<<<<<<<<<<<
\setlength{\imagewidth}{0.7\textwidth} % set the image width
\newcommand{\TextFont}{\sffamily\small}% set the side text font
\setlength{\TextWidth}{0.2\textwidth}% set the width of the side text
\setlength{\TextXshift}{2ex}% horizontal shift of the side text
\setlength{\TextYshift}{0pt}% vertical shift of the side text

\newcommand{\InsertImageText}[2]{% \InsertImageText{<image name>}{<side text>}
    \begin{tikzpicture}
        \node (A)[inner xsep=0pt,inner ysep=2ex] {\includegraphics[width=\imagewidth]{#1}};
        \node[%
        font=\TextFont,
        align =flush left,
        text width=\TextWidth,
        right= \TextXshift, 
        yshift =-\TextYshift,
        inner sep= 0pt] at (A.east) {#2};
    \end{tikzpicture}   
}
%****************************************

\begin{document}
\begin{itemize}
    \item \textbf{Fase B--C} -- \kant[1]
    
    \InsertImageText{example-image}{As we have already seen, what we have alone been able   to show is that the objects in space and time would be falsified.}
    
    \item \textbf{Fase C--D} -- \kant[2]
\end{itemize}

\end{document}

选项

使用表格环境可以获得等效的结果,在此示例中,使用nicematrix包及其便捷的\Block命令将垂直居中的内容插入表格单元格。

\documentclass{article}

\usepackage{graphicx}

\usepackage{kantlipsum} % ONLY for dummy text   

%**************************************** added 
\usepackage{nicematrix}

\newlength{\imageheight}
\newlength{\imagewidth}
\newlength{\TextWidth}
\newlength{\TextXshift}
\newlength{\TextYshift}
% define the parameters  here <<<<<<<<<<<<<<<
\setlength{\imagewidth}{0.7\textwidth} % set the image width
\newcommand{\TextFont}{\sffamily\small}% set the side text font
\setlength{\TextWidth}{0.2\textwidth}% set the width of the side text
\setlength{\TextXshift}{2ex}% horizontal shift of the side text

\newcommand{\InsertImageText}[2]{% \InsertImageText{<image name>}{<side text>}
\vspace*{2ex}\setlength{\tabcolsep}{0pt}
\begin{NiceTabular}{l@{\hspace{\TextXshift}}Wc{\TextWidth}}
    \Block{1-1}{\includegraphics[width=\imagewidth]{#1}} & \Block[l]{1-1}{\TextFont #2}\\
\end{NiceTabular}
}
%****************************************

\begin{document}
\begin{itemize}
    \item \textbf{Fase B--C} -- \kant[1]
    
    \InsertImageText{example-image}{As we have already seen, what we have alone been able   to show is that the objects in space and time would be falsified.}
    
    \item \textbf{Fase C--D} -- \kant[2]
\end{itemize}

\end{document}

相关内容