[Tex/LaTex] Text block near image

spacingtikz-pgfvertical alignment

I'm creating a photo address book for the community. Near the photo there are 3 text blocks 1. Names, 2. Address/phone/email and 3. native place). I want each of this blocks to be at top, center and bottom respectively.

When I use every node anchor = center, there is equal space at and bottom of the text. But if the space is between the text blocks then it would be great.

enter image description here

Excerpt of the tex file is below:

\documentclass[10pt,a5paper]{book}
\usepackage{graphicx,pdfpages}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage{scalefnt}
\usepackage[top=15mm, bottom=15mm, left=10mm, right=10mm]{geometry}

\usetikzlibrary{positioning,shapes.geometric,%
  decorations.pathreplacing,decorations.pathmorphing,shapes,%
  matrix,shapes.symbols,decorations.markings,shadows}

\pagestyle{plain}
\addtolength{\oddsidemargin}{+5mm}
\addtolength{\evensidemargin}{-5mm}
\begin{document}
%\includepdfmerge{/home/chidamba/Downloads/51_nov26.pdf,-}
\setcounter{page}{3}
\scalefont{0.9}

\begin{tikzpicture}
[every node/.style={anchor=north}]
\matrix [fill={rgb:black,1;white,8}] (profile1)
{
\node [text width=44mm] {
Xxxxxxx Xxxxxxxx \\
\vspace{2ex}
\begin{raggedleft}
Xxxxxxxxx, XX 99999 \\
\vspace{2ex}
xxxxxxx@xxxxx.xxx \\
\end{raggedleft}
\vspace{2ex}
Xxxxxxxxx \\
Xxxxxxxxxxxxxx Xxxxx \\
(Xxxxxxxxxxxx) \\
}; &&
\node { 
\includegraphics[width=70mm,height=50mm,keepaspectratio]{\detokenize{/home/chidamba/Downloads/pn_photos/Chettinad_house.jpg}}
}; \\ 
};

\matrix [fill=blue!15,below=2mm] at (profile1.south) (profile2)
{
\node { 
\includegraphics[width=70mm,height=50mm,keepaspectratio]{\detokenize{/home/chidamba/Downloads/pn_photos/Chettinad_house.jpg}}
}; && 
\node [text width=44mm] {
\begin{raggedleft}
Xxxxxx Xxxxxxxxx \\
Xxxxx Xxxxxx \\
Xxxxxxxxxxx Xxxxxx Xx \\
Xxxxxx Xxxxxxxx Xxxxxx \\
Xxxxxxxxx Xxxxx \\
\end{raggedleft}
\vspace{2ex}
9999 Xxxxx Xxxxx \\
Xxxxxxxxxx, XX 99999 \\
\vspace{2ex}
(999) 999-9999 \\
xxxxxxx@xx.xxxxxxxxxxx.xxx \\
xxxxx.xxxxxx@xxxxx.xxx \\
\vspace{2ex}
\begin{raggedleft}
Xxxxxxxx \\
Xxxxxxxx Xxxxx \\
\end{raggedleft}
}; \\
};

\matrix [fill={rgb:black,1;white,8},below=2mm] at (profile2.south) (profile3)
{
\node [text width=44mm] {
Xxxxxx Xxxxxxxxxxxxxx \\
Xxxxxx Xxxxxx \\
Xxxxx \\
\vspace{2ex}
\begin{raggedleft}
99999 Xxxxxxxx Xxxxxxx \\
Xxxxxxxxx, XX 99999 \\
\vspace{2ex}
(999) 999-9999 \\
xxxxxx\_xxxxxx@xxxxx.xxx \\
xxxxxxxxxxxx@xxxxxxx.xxx \\
\end{raggedleft}
\vspace{2ex}
Xxxxxxxxx \\
Xxxxxxxxx Xxxxx \\
}; &&
\node { 
\includegraphics[width=70mm,height=50mm,keepaspectratio]{\detokenize{/home/chidamba/Downloads/pn_photos/Chettinad_house.jpg}}
}; \\ 
};

\end{tikzpicture}
\newpage
\end{document}

Best Answer

Here is a macro version of the type of alignment you are looking for:

enter image description here

With this approach, the names block at the top will stay at the top and grow downward as you add more names, the address block grows from the center of the image, and the bottom block grows upwards are you add more lines.

Further Enhancements

  • You could define another macro to place the text on the right side as well. Personally, I would use the xparse package to define a starred variant \AddImage* which places the text on the right.

Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}

\usetikzlibrary{backgrounds}

\pgfdeclarelayer{background layer} 
\pgfdeclarelayer{foreground layer} 
\pgfsetlayers{background layer,main,foreground layer}

\newcommand{\AddImage}[5][]{%
    % #1 = options for bounding box
    % #2 = \includegraphics command for image
    % #3 = Names
    % #4 = Address
    % #5 = Other Text
    %
    \begin{tikzpicture}
    \begin{pgfonlayer}{foreground layer}% default
    \node [inner sep=0pt] (MyPictureNode) {#2};
    \node [anchor=north east, align=right] at (MyPictureNode.north west) {#3};
    \node [anchor=east, align=right] at (MyPictureNode.west) {#4};
    \node [anchor=south east, align=right] at (MyPictureNode.south west) {#5};
    \end{pgfonlayer}
    %
    \begin{pgfonlayer}{background layer}
    \draw [fill=gray!20, draw=brown, thick, #1]
        ([shift={(-3pt,-3pt)}]current bounding box.south west) rectangle 
        ([shift={( 3pt, 3pt)}]current bounding box.north east);
    \end{pgfonlayer}
    \end{tikzpicture}
}
\begin{document}
\AddImage
    {\includegraphics[width=70mm,height=50mm,keepaspectratio]{../images/EiffelWide.jpg}}
    {Name 1 \\ Name 2 \\ Name 3}
    {123 Main Street \\ Anytown, Country \\ Phone}
    {Some Text \\ More Text}

\AddImage[draw=blue, ultra thick, fill=red!25]
    {\includegraphics[width=70mm,height=50mm,keepaspectratio]{../images/EiffelWide.jpg}}
    {Name 1 \\ Name 2 \\ Name 3}
    {123 Main Street \\ Anytown, Country \\ Phone}
    {Some Text \\ More Text}
\end{document}