使用 LaTeX 在三列布局中将图像与项目符号对齐

使用 LaTeX 在三列布局中将图像与项目符号对齐

我正在使用 LaTeX 创建具有三列结构的文档。在我的布局中,第一列用于主题,第二列包含项目要点列表,第三列包含不同大小的图像。

我的 LaTeX 代码如下:

\documentclass[11pt,ngerman]{moderncv}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\usepackage[UKenglish]{babel}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{graphicx}
\usepackage{fontawesome5}
\usepackage{verbatim}
\newcommand{\cmmnt}[1]{}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
\providecommand{\tabularnewline}{\\}
\usepackage[super]{nth}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\moderncvtheme[blue]{classic}
\usepackage{lastpage}
\firstname{firstName}
\familyname{lastName}
\title{topic}

\address{}

\usepackage{graphicx}
\newcommand{\Csharp}{%
    {\settoheight{\dimen0}{C}C\kern-.05em \resizebox{!}{\dimen0}{\raisebox{\depth}{\#}}}}

\makeatother
\usepackage{babel}
\usepackage{xpatch}

%\usepackage[absolute,overlay]{textpos}
\usepackage{textpos}
\usepackage{wrapfig}

\xpatchcmd{\cventry}{.\strut}{\strut}{}{}
\begin{document}
    \maketitle  
\vspace{-0.9cm}


\vspace{-0.3cm}
\section{Section}
\vspace{0.2cm}

\cventry{Topic}{
    \begin{minipage}[t]{0.6\textwidth}
        \begin{itemize} 
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}%
    \hspace{-5cm}
    \begin{minipage}[t]{0.3\textwidth}
        \raggedleft 
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.5cm]{example-image-a}}
        }
    \end{minipage}
}{}{}{}{}{}



\cventry{Topic}{
    \begin{minipage}[t]{0.6\textwidth}
        \begin{itemize} 
            \item {\normalfont Point1}
            \item {\normalfont Point2}
        \end{itemize}
    \end{minipage}%
    \hspace{-4.855cm}
    \begin{minipage}[t]{0.3\textwidth}
        \raggedleft 
        \raisebox{-0.5\height}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.6cm, width=1.8cm]{example-image-a}}
        }
    \end{minipage}
}{}{}{}{}{}


\cventry{Topic}{
    \begin{minipage}[t]{0.6\textwidth}
        \begin{itemize} 
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}%
    \hspace{-3.05cm}
    \begin{minipage}[t]{0.3\textwidth}
        \raggedleft 
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.5cm]{example-image-a}}
        }
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.5cm]{example-image-b}}
        }
    \end{minipage}
}{}{}{}{}{}

\cventry{Topic}{
    \begin{minipage}[t]{0.6\textwidth}
        \begin{itemize} 
            \item {\normalfont Point1}
            \item {\normalfont Point2}
        \end{itemize}
    \end{minipage}%
    \hspace{-3.05cm}
    \begin{minipage}[t]{0.3\textwidth}
        \raggedleft 
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.5cm]{example-image-a}}
        }
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.6cm, width=1.8cm]{example-image-b}}
        }
        \raisebox{-0.5\height - 0.3cm}{ 
            \href{https://www.google.com/}{\includegraphics[height=1.5cm]{example-image-c}}
        }
    \end{minipage}
}{}{}{}{}{}

\end{document}

在此处输入图片描述

我面临的挑战是将第三列中的图像与第二列中的要点对齐。具体来说,我想实现两件事:

  1. 确保一行中的所有图像相对于项目符号都垂直居中。
  2. 对齐图像,使得每行中的第一个图像位于前一行中第一个图像的正下方,第二个图像位于第二个图像的正下方,依此类推。

图像没有按预期与项目符号对齐。

最后,期望的结果应该是这样的: 在此处输入图片描述

我将非常感激任何有关如何完成这些调整的指导或建议。非常感谢您的帮助!

致以最诚挚的问候,
丹尼尔

我也发过同样的问题这里

答案1

经过彻底的调查,我制定了文档中图像布局和定位的解决方案。

在此处输入图片描述

该解决方案的关键方面是:

  1. 水平居中:所有图片均相对于其中心点水平居中。每张图片的中心几乎与要点列表完美对齐。

  2. 垂直对齐:位于彼此下方的图片也将居中。每张图片的中间点直接对齐在彼此下方,从而形成视觉上连贯的垂直线。

  3. 可调间距:图片之间的距离可以单独调整。这种灵活性允许精确控制间距,从而实现量身定制且美观的布局。

这是乳胶代码:

\section{Section}

\newlength{\tabularcolumnwidth}
\setlength{\tabularcolumnwidth}{7cm}

\newlength{\minipagewidth}
\setlength{\minipagewidth}{2cm}

\newlength{\midoffset}
\setlength{\midoffset}{-0.25cm}


\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic1}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.5cm, width=1.5cm]{example-image-a}}}
    \end{minipage}
\end{tabular}

\vspace{1.5cm}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic2}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1cm, width=2cm]{example-image-a}}}
    \end{minipage} 
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=2cm, width=1cm]{example-image-b}}}
    \end{minipage}
\end{tabular}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic3}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
            \item {\normalfont Point4}
            \item {\normalfont Point5}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.5cm, width=1.3cm]{example-image-a}}}
    \end{minipage} 
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1cm, width=2cm]{example-image-b}}}
    \end{minipage}
& 
    \hspace{1cm}
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=3cm, width=1.8cm]{example-image-c}}}
    \end{minipage}
\end{tabular}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic4}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-a}}}
    \end{minipage} 
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \hspace{2cm}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-b}}}
    \end{minipage}
& 
    \hspace{1cm}
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-c}}}
    \end{minipage}
\end{tabular}

要在表格中图像的右下角插入链接图标,请使用以下代码片段。

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic1}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \href{https://www.google.com/}{
            \begin{overpic}[width=1.5cm, height=1.5cm]{example-image-a}
                \put(1.5cm-0.5cm,0.0cm){\href{https://www.google.com/}{\includegraphics[height=0.5cm, width=0.5cm]{icon_symbol.png}}}
            \end{overpic}
        }
    \end{minipage}

\end{tabular}

在此处输入图片描述

当然,这个代码还可以改进,但这是一个良好的开端。

这是完整的代码:

\documentclass[11pt,ngerman]{moderncv}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[UKenglish]{babel}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[percent]{overpic}
\usepackage{fontawesome5}
\usepackage{verbatim}
\newcommand{\cmmnt}[1]{}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
\providecommand{\tabularnewline}{\\}
\usepackage[super]{nth}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\moderncvtheme[blue]{classic}
\usepackage{lastpage}
\firstname{firstName}
\familyname{lastName}
\title{topic}

\address{}

\usepackage{graphicx}
\newcommand{\Csharp}{%
    {\settoheight{\dimen0}{C}C\kern-.05em \resizebox{!}{\dimen0}{\raisebox{\depth}{\#}}}}

\makeatother
\usepackage{babel}
\usepackage{xpatch}

%\usepackage[absolute,overlay]{textpos}
\usepackage{textpos}
\usepackage{wrapfig}

\xpatchcmd{\cventry}{.\strut}{\strut}{}{}
\begin{document}
    \maketitle  

\section{Section}
\vspace{0.2cm}

\newlength{\tabularcolumnwidth}
\setlength{\tabularcolumnwidth}{7cm}

\newlength{\minipagewidth}
\setlength{\minipagewidth}{2cm}

\newlength{\midoffset}
\setlength{\midoffset}{-0.25cm}


\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic1}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \href{https://www.google.com/}{
            \begin{overpic}[width=1.5cm, height=1.5cm]{example-image-a}
                \put(1.5cm-0.5cm,0.0cm){\href{https://www.google.com/}{\includegraphics[height=0.5cm, width=0.5cm]{example-image}}}% icon_symbol.png replaced to make the example work everywhere
            \end{overpic}
        }
    \end{minipage}

\end{tabular}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic2}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \begin{overpic}[height=1cm, width=2cm]{example-image-a}
            \put(2cm-0.5cm,0.0cm){\href{https://www.google.com/}{\includegraphics[height=0.5cm, width=0.5cm]{example-image}}}% icon_symbol.png replaced to make the example work everywhere
        \end{overpic}
    \end{minipage}
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=2cm, width=1cm]{example-image-b}}}
    \end{minipage}
\end{tabular}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic3}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
            \item {\normalfont Point4}
            \item {\normalfont Point5}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.5cm, width=1.3cm]{example-image-a}}}
    \end{minipage} 
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1cm, width=2cm]{example-image-b}}}
    \end{minipage}
& 
    \hspace{1cm}
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=3cm, width=1.8cm]{example-image-c}}}
    \end{minipage}
\end{tabular}

\begin{tabular}{p{\tabularcolumnwidth}ccc}
\cventry{Topic4}{
    \begin{minipage}[t]{0.5\textwidth}
        \begin{itemize}
            \item {\normalfont Point1}
            \item {\normalfont Point2}
            \item {\normalfont Point3}
        \end{itemize}
    \end{minipage}
}{}{}{}
&
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-a}}}
    \end{minipage} 
& 
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \hspace{2cm}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-b}}}
    \end{minipage}
& 
    \hspace{1cm}
    \begin{minipage}{\minipagewidth}
        \centering
        \vspace{\midoffset}
        \raisebox{-.5\height}{\href{https://www.google.com/}{\includegraphics[height=1.8cm, width=1.8cm]{example-image-c}}}
    \end{minipage}
\end{tabular}

\end{document}

相关内容