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.

Here is a minimal working example

%!TEX TS-program = xelatex
\documentclass{article}

%%%%%%%%%%
% Colors %
%%%%%%%%%%
\usepackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=gray]{Helvetica Neue Light}

%%%%%%%%%%%%%%%%%
% Graphic tools %
%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}


%%%%%%%%%%
% Header %
%%%%%%%%%%
 \begin{tikzpicture} [remember picture,overlay]
   \node[](name)[align = left, inner sep = 0] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
   \fontsize{20}{5pt}\selectfont{My function}};
   \draw (name.north west) -- +(20cm, 0);
   \draw (name.south west) -- +(20cm, 0);
   \node[](about)[align=left,inner sep=0, right=5.0cm of name.north east, anchor=north west]{%
   \fontsize{12pt}{12pt}\selectfont{mymail@mail.com} \\
   \fontsize{12pt}{12pt}\selectfont{+45 555 555} \\%
   \fontsize{12pt}{12pt}\selectfont{my adress} \\   
   \fontsize{12pt}{12pt}\selectfont{zipcode City} \\
   };
 \end{tikzpicture}

\end{document}

gives the following result

latex1

I would like the text in the rightmost node to "fill" the node i.e. to be perfectly aligned on the two lines I draw on the picture. Is it possible? Maybe using a minipage? In the same idea, is it possible to force the text to fill the node horizontally so that the text is justified both right and left ?

EDIT: it seems the justified text can be obtained playing with the node options text width, minimum width and justified text. However, those options do not seem to work as soon as a "." characted is entered in the character screen as illustrated by the two following pictures.

justifiedtext1

justifiedtext2

The related codes adaptations are the following ones.

 \begin{tikzpicture} [remember picture,overlay]
   \node[](name)[align = left, inner sep = 0] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
   \fontsize{20}{5pt}\selectfont{My function}};
   \draw (name.north west) -- +(20cm, 0);
   \draw (name.south west) -- +(20cm, 0);
   \node[](about)[draw=black, thin, align=left,inner sep=0, right=5.0cm of name.north east, anchor=north west, text width=4cm, minimum width=4cm, text justified]{%
   \fontsize{12pt}{12pt}\selectfont{mymail@mailcom} 
   \fontsize{12pt}{12pt}\selectfont{+45 555 555} 
   \fontsize{12pt}{12pt}\selectfont{my adress}   
   \fontsize{12pt}{12pt}\selectfont{zipcode City} 
   };
 \end{tikzpicture}


 \begin{tikzpicture} [remember picture,overlay]
   \node[](name)[align = left, inner sep = 0] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
   \fontsize{20}{5pt}\selectfont{My function}};
   \draw (name.north west) -- +(20cm, 0);
   \draw (name.south west) -- +(20cm, 0);
   \node[](about)[draw=black, thin, align=left,inner sep=0, right=5.0cm of name.north east, anchor=north west, text width=4cm, minimum width=4cm, text justified]{%
   \fontsize{12pt}{12pt}\selectfont{mymail@mail.com} 
   \fontsize{12pt}{12pt}\selectfont{+45 555 555} 
   \fontsize{12pt}{12pt}\selectfont{my adress}   
   \fontsize{12pt}{12pt}\selectfont{zipcode City} 
   };
 \end{tikzpicture}
share|improve this question
1  
A minimal example should start with \documentclass and end width \end{document}. –  Marco Daniel Jun 3 '13 at 15:23
    
you are right. I modified the code accordingly –  Jérémy Bulle Jun 3 '13 at 15:40
    
Regarding your second point: do you want the email address etc pushed right over to the far right (but still left-aligned)? –  John Wickerson Jun 3 '13 at 16:27
    
No, what I want is (I think) called a justified text in Tikz. I can obtain it using the option text width, minimal width and text justified options for a node in tikz. Problem is, the code does not work as soon as a "." characted is entered. I edited my answer to show this possibility –  Jérémy Bulle Jun 3 '13 at 19:32

4 Answers 4

The vertical filling you can do when you measure height with the help of \pgfgetlastxy:

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}

\newcommand{\computeheight}[2]% name of node, name of targetmacro
{ \path (#1.south west);
  \pgfgetlastxy{\xsw}{\ysw}
  \path (#1.north east);
  \pgfgetlastxy{\xne}{\yne}
  %\pgfmathsetlengthmacro{\nodewidth}{\xne-\xsw}% not needed here
  \pgfmathsetlengthmacro{\nodeheight}{\yne-\ysw}
  %\xdef\widthofnode{\nodewidth}
  \expandafter\xdef\csname #2\endcsname{\nodeheight}
}

\begin{document}

\begin{tikzpicture} [remember picture,overlay]
  \node[right](name)[align = left, inner sep = 2pt] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
  \fontsize{20}{5pt}\selectfont{My function}};

    % get height of node "name"
  \computeheight{name}{nameheight}

  \draw (name.north west) -- +(18cm, 0);
  \draw (name.south west) -- +(18cm, 0);

    % helper coordinate
    \coordinate[right=5.0cm of name.north east, anchor=north west] (about);
    % the data you want to use; the {} is for protecting commas in the entries,
    % so it's not neccessary here
    \foreach \t [count=\c] in {{mymail@mail.com},{+45 555 555},{my adress},{zipcode City}}
    {   \pgfmathsetlengthmacro{\topdistance}{(\c-1)*\nameheight/4+\nameheight/4*0.5}
        \node[below=\topdistance of about,align=left,anchor=west] (about\c) {\fontsize{12pt}{12pt}\selectfont{\t}};
    }
\end{tikzpicture}

\end{document}

Output

enter image description here

share|improve this answer

This is flat out MS Word type, terrible typesetting and I hope you have a valid reason for using this. Also I hope your address fills the line.

For text without a linebreak, TikZ has align=justify option. You can push things around with spaces instead of a line break.

 \begin{tikzpicture} [remember picture,overlay]
   \node[](name)[align = left, inner sep = 0] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
   \fontsize{20}{5pt}\selectfont{My function}};
   \draw (name.north west) -- +(20cm, 0);
   \draw (name.south west) -- +(20cm, 0);
   \node[](about)[inner sep=0, right=5.0cm of name.north east, anchor=north west,align=justify, text width=3.5cm]{%
   \fontsize{12pt}{12pt}\selectfont{mymail@mail.com}
   \fontsize{12pt}{12pt}\selectfont{+45 555 555}\hspace{2em}
   \fontsize{12pt}{12pt}\selectfont{Wallie Street}\hspace{3em}
   \fontsize{12pt}{12pt}\selectfont{1234AB\hfill Lyon}
   };
 \end{tikzpicture}

enter image description here

-I am calling for the follow-up on my job interview...

-Zero taste. Don't call us again.

share|improve this answer
    
Your remark concerning typesetting is interesting. Do you have any website teaching the basics of typesetting? It could be useful. –  Jérémy Bulle Jun 4 '13 at 16:06

To get the "fill" effect you want, you could use this

\fontsize{12pt}{12pt}\selectfont{mymail@mail.com} \\[3pt]
\fontsize{12pt}{12pt}\selectfont{+45 555 555} \\[3pt]
\fontsize{12pt}{12pt}\selectfont{my adress} \\[3pt]   
\fontsize{12pt}{12pt}\selectfont{zipcode City}

enter image description here

share|improve this answer

The vertical filling can be achieved with a small computation inside a \foreach loop:

%!TEX TS-program = xelatex
\documentclass{article}

%%%%%%%%%%
% Colors %
%%%%%%%%%%
\usepackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=gray]{Arial}

%%%%%%%%%%%%%%%%%
% Graphic tools %
%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}

\begin{document}


%%%%%%%%%%
% Header %
%%%%%%%%%%
 \begin{tikzpicture} [remember picture,overlay]
   \node[](name)[align = left, inner sep = 0] {\fontsize{42pt}{0pt}\selectfont{My Name} \\
   \fontsize{20}{5pt}\selectfont{My function}};
   \draw (name.north west) -- +(20cm, 0);
   \draw (name.south west) -- +(20cm, 0);
%    \node[](about)[align=left,inner sep=0, right=5.0cm of name.north east, anchor=north west]{%
%    \fontsize{12pt}{12pt}\selectfont{mymail@mail.com} \\
%    \fontsize{12pt}{12pt}\selectfont{+45 555 555} \\%
%    \fontsize{12pt}{12pt}\selectfont{my adress} \\   
%    \fontsize{12pt}{12pt}\selectfont{zipcode City} \\
%    };
   \node(abouttop)[align=left,inner sep=0, right=5.0cm of name.north east, anchor=north west]{mymail@mail.com};
   \node(aboutbottom)[align=left,inner sep=0, right=5.0cm of name.south east, anchor=south west]{zipcode City};
   \newcommand{\nodelist}{{+45 555 555},{my adress}}
   \newcommand{\nodelistlength}{2} %try to calculate this automatically
   \foreach \nodetext [count=\nodenumber] in \nodelist
    {
    \node[align=left,inner sep=0,anchor=base west] at ($(abouttop.base west)!\nodenumber/(1+\nodelistlength)!(aboutbottom.base west)$){\nodetext};
    }
 \end{tikzpicture}

\end{document}

I'm not good at list computations in LaTeX, that's why it's a little bit hacked. This answer can be improved by:

  1. Computing the length of the list of lines automatically.
  2. Just submitting the 4 lines and stripping the first and last line off in order to place it explicitly automatically.
  3. Use tikz styles.
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.