以不同方式对齐三列;使用图片、手动拆分和环绕文本

以不同方式对齐三列;使用图片、手动拆分和环绕文本

我正在尝试创建一个从左到右有三列的情况:

一个图像的顶部边缘与中心列的顶部和其自身的左侧对齐;

一种是环绕式文本,带有手动换行。一些文本将左对齐,一些将右对齐;

其中一个图像的底边与中心列的底部对齐。

我尝试过使用三个小页面,也尝试过表格(参见 mwe)。我尝试过类似的解决方案使用小页面将图像和文本对齐到顶部,但我仍然无法弄清楚如何让右列的图像与底部对齐。

\documentclass{article}%

\usepackage{graphicx}%

\newlength{\myheadskip}
\setlength\myheadskip{2ex plus 1ex minus 0.5ex}
\newlength{\imagewid}
\setlength{\imagewid}{0.162\textwidth}


\newcommand{\partnerimageone}[6]{
\vspace{1.0\myheadskip}
\begin{minipage}[b][][t]{0.18\textwidth}
\flushleft
% \vspace{0pt}
\includegraphics[height=\imagewid]{#5}
% \vspace*{\fill}
\end{minipage}
\begin{minipage}[c]{0.62\textwidth}
\begin{flushleft}
\textbf{\Large #1}

\emph{#2}\vspace{-0.5\myheadskip}
\end{flushleft}

\begin{flushright}
\textbf{\Large #3}

\emph{#4}
\end{flushright}
\end{minipage}
\begin{minipage}[b][][b]{0.18\textwidth}
\flushright
\vspace*{\fill}
\includegraphics[height=\imagewid]{#6}
\end{minipage}
}

\newcommand{\partnerimagetwo}[6]{
\vspace{1.0\myheadskip}
\begin{tabular}{@{}p{0.18\textwidth} p{0.62\textwidth} p{0.18\textwidth}}
\vspace{-2ex}\includegraphics[height=\imagewid]{#5} & 
\textbf{\Large #1} \newline
\emph{#2}\vspace{-0.5\myheadskip} \newline
{\flushright\hfill\textbf{\Large #3}} \newline
{\raggedleft\emph{#4}} &
% \end{flushright} & 
\vspace*{\fill}
\includegraphics[height=\imagewid]{#6}
\end{tabular}
}

\begin{document}

\partnerimageone{
Your Favorite Food Truck
}{
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you\vspace{3ex}
}{
A Nice Bakery
}{
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
}{l_sq}{r_sq}

\partnerimagetwo{
Your Favorite Food Truck
}{
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you\vspace{3ex}
}{
A Nice Bakery
}{
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
This place is magnificent! 
}{l_sq}{r_sq}

\end{document}

姆韦

答案1

以下是环境提供的一个选项foodstuff

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx,tabularx,environ}
\usepackage{lipsum}

\makeatletter
\newcommand{\@leftimage}{}
\newcommand{\@rightimage}{}
\let\leftimage\@gobble
\let\rightimage\@gobble
\long\def\extractleftimage#1\leftimage#2#3\null{\renewcommand{\@leftimage}{#2}}
\long\def\extractrightimage#1\rightimage#2#3\null{\renewcommand{\@rightimage}{#2}}
\NewEnviron{foodstuff}{%
  \expandafter\extractleftimage\BODY\null% Extract left image
  \expandafter\extractrightimage\BODY\null% Extract right image
  \noindent
  \begin{tabularx}{\textwidth}{
      @{} p{.2\textwidth}% Left image column
      X% Center text column
      p{.2\textwidth} @{}}% Right image column
    & \strut%
    \if$\@leftimage$\else\llap{\raisebox{\dimexpr-\height+.7\normalbaselineskip}[0pt][0pt]{%
      \includegraphics[width=.2\textwidth]{\@leftimage}\hspace*{\tabcolsep}}}\fi%
    \BODY\par
    \vspace*{-\normalbaselineskip}\leavevmode\hfill%
    \strut%
    \if$\@rightimage$\else\rlap{\hspace*{\tabcolsep}\raisebox{0pt}[0pt][0pt]{%
      \includegraphics[width=.2\textwidth]{\@rightimage}}}\fi &
  \end{tabularx}
}
\makeatother
\newcommand{\heading}[1]{{\large\bfseries #1\par}}
\begin{document}

\begin{foodstuff}
  \leftimage{example-image-a}% Specify left column image
  \rightimage{example-image-b}% Specify right column image
  \heading{Lorem ipsum dolor sit amet}
  \lipsum[1]

  \bigskip

  \heading{Nullam sagittis neque ac lacus}
  \raggedleft\lipsum[2]
\end{foodstuff}

\end{document}

使用环境允许您自由地设计内部/中心列内容以满足您的需要。

左、右(图像)列的宽度为.25\textwidth,中间列为tabularx X-柱子。

要求是你必须指定\leftimage \rightimage在环境内部foodstuff。如果您不使用图像,您仍然需要使用\leftimage{}(或\rightimage{}),因为它们必然是环境主体的一部分。

答案2

它再一次\raisebox拯救了我们。

\documentclass{article}
\usepackage{graphicx}
\usepackage{mwe}% for image

\newsavebox{\tempbox}
\newlength{\tempheight}
\newlength{\tempdepth}

\begin{document}

\savebox{\tempbox}{\parbox[c]{0.63\textwidth}
{\hfil\textbf{Your Favorite Food Truck}\newline
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you
Offering gourmet local eats prepared daily for you}}

\settoheight{\tempheight}{\usebox{\tempbox}}
\settodepth{\tempdepth}{\usebox{\tempbox}}% not quite equal

\noindent\raisebox{\tempheight}{\raisebox{-\height}% ugly, but it works
{\includegraphics[width=0.15\textwidth]{example-image-a}}}\hfill
\usebox{\tempbox}\hfill
\raisebox{-\tempdepth}{\includegraphics[width=0.15\textwidth]{example-image-b}}

\end{document}

垂直对齐

相关内容