1

How do I vertically align the title and the image along their center, while keeping a fixed space between the title and the authors, like so?

enter image description here

I want to independently align a piece of text (the title) horizontally with some other piece of text (authors), and vertically with an image, without the latter influencing the amount of space separating the title and the author.

Unfortunately, I only know how to align things with tables in LaTeX, and I don't think this is possible. This seems to be one of those things that is significantly easier to do in a visual editor than in LaTeX.

Here is an MWE

\documentclass{article}
\usepackage{tabularx}
\usepackage{graphicx}

\begin{document}
\begin{tabularx}{\textwidth}{@{} >{\arraybackslash\raggedleft}m{0.2\linewidth} m{1.5mm} m{0.5\linewidth} @{}}
      \includegraphics[width=15mm]{example-image}
    & &    {\huge\bfseries Lorem Ipsum yayaya}
    \\
    \textsc{Cool}
    & &    Author One, Author Two
  \end{tabularx}
\end{document}

enter image description here The height of the first row is determined by the image.

The problem is that the space beneath the title varies with the length of the title. If I make the title very long, we get enter image description here

And now the height of the row is determined by the title instead of the image!

I tried some hacks which forced the vbox of the image to 0, which helped a bit but it messed up the center-alignment. Another way of hacking this would be to set the height of the author-row differently depending on the amount of lines, but I feel like there is a more elegant way to solve this. A solution without tables would also be perfectly fine.

EDIT Apologies, I think I did not explain myself correctly. I am creating a template for a journal and the titles of the articles tend to vary a lot. Therefore I would like to create a template which will automatically keep the image centered with the title, and keep the distance between the title and the author fixed. This would amount to keeping the green lines the same height in the image below (which was created manually using Simon's suggestion of NiceTabular, although this shifts the center-alignment somewhat).

enter image description here

1
  • Please see the updated answer, adding another approach. Jul 9, 2021 at 20:12

1 Answer 1

1

UPDATE after more specific the requirements.

If you want to create a template of a layout, it is best to use a tool that emulates a layout designer program: the xcoffin package.

The working principles and the work flow are the same. You put your contents in boxes (text, tables, figures, etc.) choosing their font, size, scale, colors, etc.

Then you assemble your desired layout, first choosing their relative positions of their centers or edges or corners, and then adding the vertical and horizontal separation between the boxes. It should not be necessary to calculate absolute coordinates.

In this case we will use 4 boxes: the image, the title, the authors and one word to the left.

Your requirements so far are:

(1) The title may vary in font or in number of lines.

(2) The center of the box image must be horizontally aligned with the center of box title, regardless of its vertical size.

(3) The right edge of the box image should be horizontally separated from the left edge of the box title by distance X.

(4) The top of the box authors must be vertically separated from the baseline of the last line of the box title by a distance Y, and their left borders must be aligned.

(5) The box with the word "Cool" and the box authors should have their baselines aligned, and the right edge of the first one separated by the distance X from the left border of the second.

(6) (added by me) The designer should be able to choose X, Y and the title format without the need to change the basic layout. (Needs to be done only once).

(7) (added by me) The end user must be able to enter the different contents without risk of altering the template by mistake.

Title one line long. H red line = 50pt, V green line = 20pt.

L1

L2

Title three lines long. Compare the alignment with the one line.

L3

\documentclass{article}

\usepackage{graphicx} % needed

\usepackage{kantlipsum}% dummy text
%%************ show the page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\usepackage{xcoffins} % needed
%% Allocate
\NewCoffin\MainFrame % collecting frame
\NewCoffin\LeftImage
\NewCoffin\Coolw
\NewCoffin\Authorx
\NewCoffin\Titlex
\newlength{\IntraImage} 
\newlength{\IntraTitle}

\begin{document}

%% Fill the content <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< by the user
\newcommand{\aTitle}{Lorem Ipsum Title\\ Which is too long\\ Too long} % a three lines title
\newcommand{\aLogo}{\includegraphics[width=15mm]{example-image}}
\newcommand{\aAuthors}{Author One, Author Two}
\newcommand{\aWord}{\textsc{Cool}}

%\renewcommand{\aTitle}{Which is too long\\ Too long} % test a two lines title
%\renewcommand{\aTitle}{Which is too long} % test a single line title
%%***********************************************************

%% Design: format of the title, H distance image-title, V distance title-authors <<<<<<<<<<<<
\newcommand{\formatTitle}{\noindent\huge\bfseries} % format the title
\setlength{\IntraImage}{50pt}  % horizontal sepation
\setlength{\IntraTitle}{20pt}  % vertical separation
%%***********************************************************

%% Set
\SetHorizontalCoffin\LeftImage{\aLogo}
\SetHorizontalCoffin\Coolw{\aWord}
\SetHorizontalCoffin\Authorx{\aAuthors}
\SetVerticalCoffin\Titlex{0.7\textwidth}{\formatTitle\aTitle}

% Assembly 
\JoinCoffins\MainFrame[l,t]\LeftImage[l,t] % put the image in the frame
\JoinCoffins\MainFrame[r,vc]\Titlex[l,vc](\IntraImage,0pt) % join the title at an horizontal distance \IntraImage
\JoinCoffins\MainFrame[\Titlex-l,\Titlex-b]\Authorx[l,vc](0pt,-\IntraTitle) % join the authors with title and dowm \IntraTitle
\JoinCoffins\MainFrame[\Authorx-l,\Authorx-B]\Coolw[r,B](-\IntraImage,0pt) % join the word aligned with authors

%Typeset
\noindent\TypesetCoffin\MainFrame  %put the assambly in the page current insertion point

\vspace*{40pt}
\kant[1]
\end{document}

Brief explanation of the workflow

\Set... fills the content (done 4 times)

\Join... set one box in relation with other (done 4 times), [r,vc] indicates the vertical center of the right border of the box, (x,y) adds an horizontal shift x and a vertical displacement y.

\Typeset puts the final content in the page in the current insertion point. It is not a float.

References

By following the example of the short manual of the package manual you will learn all that its needed to modify the design yourself.

Tschichold design: https://tex.stackexchange.com/a/86079/161015

Comments of Frank Mittelbach: https://tex.stackexchange.com/a/44159/161015

Alternative *******************************

With the package nicematrix you can align the title with the authors, at a selectable vertical distance, and also horizontally align the title with the center of the image and the authors names with the word "Cool'.

The resulting code is very simple and easy to maintain. Only one command is used.

The command \Block{}{<content>}allows to position its content and also use \\ inside, so the title will be cut were you want it.

For example \Block[l]{}{Author One, Author Two} is a cell 1 row x 1 column, left align.

The space between rows can be controlled using \\[40pt] (and \\[20pt] in the second figure) after the first row.

The blue lines show the alignment of the center of the image with the center of the title, regardless of the number of lines of the title.

p1z

Or. if you want to have the vertical space between rows be automatically set, and larger than the default value, use the directive [cell-space-top-limit=5pt] to expand the top of the cell

Using [cell-space-top-limit=5pt] for both tables.

p2z

\documentclass{article}

\usepackage{graphicx}
\usepackage{nicematrix} % added <<<<<<<<<<<<

%--------------- show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
    
    \begin{NiceTabular}{@{} m{0.2\linewidth} m{1.5mm} m{0.5\linewidth} @{}}
        \Block[r]{}{\includegraphics[width=15mm]{example-image}}
        & &\Block[l]{}<\huge\bfseries>{Lorem Ipsum Title\\ Which is too long\\ Too long} \\[40pt] % add vertical space <<
        \Block[r]{}{\textsc{Cool}} & &\Block[l]{}{Author One, Author Two}  \\
    \end{NiceTabular}
    
    \vspace*{100pt}
    
    \begin{NiceTabular}{@{} m{0.2\linewidth} m{1.5mm} m{0.5\linewidth} @{}}
        \Block[r]{}{\includegraphics[width=15mm]{example-image}}
        &   & \Block[l]{}<\huge\bfseries>{Which is too long} \\[20pt] % add vertical space <<
        \Block[r]{}{\textsc{Cool}}  &   &\Block[l]{}{Author One, Author Two}    \\
    \end{NiceTabular}
    
    \newpage
    
    \begin{NiceTabular}{@{} m{0.2\linewidth} m{1.5mm} m{0.5\linewidth} @{}}[cell-space-limits=5pt]
        \Block[r]{}{\includegraphics[width=15mm]{example-image}}
        & &\Block[l]{}<\huge\bfseries>{Lorem Ipsum Title\\ Which is too long\\ Too long} \\ % add vertical space <<
        \Block[r]{}{\textsc{Cool}}  & &\Block[l]{}{Author One, Author Two}  \\
    \end{NiceTabular}
    
    \vspace*{100pt}
    
    \begin{NiceTabular}{@{} m{0.2\linewidth} m{1.5mm} m{0.5\linewidth} @{}}[cell-space-top-limit=5pt]
        \Block[r]{}{\includegraphics[width=15mm]{example-image}}
        &   & \Block[l]{}<\huge\bfseries>{Which is too long} \\ 
        \Block[r]{}{\textsc{Cool}}  &   &\Block[l]{}{Author One, Author Two}    \\
    \end{NiceTabular}
    
\end{document}
2
  • I think my question was somewhat misleading, sorry! (see edit) What I'm looking for is a way to create a template table (or whatever) which has the correct distance between the bottom of the title and the top of the authors, no matter the length of the title. Your suggestion sort of works, but it requires manual intervention which I would like to avoid. Do you know how to do this automatically? The cell-space-limits did not produce the desired results.
    – tefkah
    Jul 9, 2021 at 12:26
  • Wow, I had no idea something existed like this for LaTeX! Thank you so much for you detailed and extremely helpful answer, and for putting me onto this incredibly helpful package! You're amazing!
    – tefkah
    Jul 11, 2021 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .