Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Welcome to TeX.SE. Thanks for including a complete document, but can you also make it compilable? –  Peter Grill Nov 27 '12 at 1:39
    
I use pdflatex on linux mint to create the pdf for this document. I don't know how to make it compilable, I'll look into it. –  user22587 Nov 27 '12 at 1:46
    
If you add a dummy example of the layout you're trying to achieve, you might get a better strategy pointed out too. It's my experience on Tex.SX that there's usually a better general way of doing things that we normally miss. –  recluze Nov 27 '12 at 1:51

2 Answers 2

up vote 2 down vote accepted

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}
share|improve this answer
    
Haha, our answers are pretty much the same thing. That's an honour for me (given your rep) :) ... Thanks for the edit, btw. –  recluze Nov 27 '12 at 1:56
1  
@recluze: Don't let my rep fool you into thinking I know what I am doing. :-) But I interpreted the question as wanting to position the text at the sides of the image. –  Peter Grill Nov 27 '12 at 1:59
    
Yes thank you very much, I want the text to be in the sides of the image. Is there a way to have bounding box for all these nodes. I have added a screenshot link. –  user22587 Nov 27 '12 at 2:01
    
You could use the fit library along with the backgrounds library for the box. –  recluze Nov 27 '12 at 2:09
    
@user22587: Updated to draw a box around the bounding box. –  Peter Grill Nov 27 '12 at 2:13

You could try using anchors with the positioning library. Personally, I think it makes for much cleaner code.

enter image description here

Here's a MWE:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}
  \begin{tikzpicture}[every node/.style={draw}]
  \node (name) {Name};
  \node [below=1em of name.south, anchor=north, minimum height=5em] (photo) {Image}; 
  \node [below=1em of photo.south, anchor=north] (info) {Other Info}; 
  \node [below=1em of info.south, anchor=north] (info two) {Other Info 2};
  \end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.