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 would like to add the month to the time span of moderncv. I order not to occupy much more space and still having a beautiful solution, I would like to do the following:
Year - Year
Month - Month
where

  • there's just one dash vertically centered in between the two dates,
  • the month is centered under the year
  • the year is stretched to the cell width if necessary
  • to occupy little space, there are no margins at all

I already did some experiments, but couldn't get the margins and the stretching right.

\documentclass{article}
\usepackage{tabu}
\usepackage[english]{babel}
\usepackage{datetime}

\newcommand* \hintscolumnwidth {0.2\textwidth} % best: 0.175\textwidth

\newcommand \testBb [4]{%
     \begin{tabu} to \hintscolumnwidth {|@{} X[c m] @{--} X[c m] @{}|}
     \hline \linespread{0}#2\newline \tiny #1&\linespread{0}#4 \newline\tiny #3 \\ \hline
     \end{tabu}}

\newcommand \testB [4]{%
     \begin{tabu} to \hintscolumnwidth {|@{} X[c m] @{}|@{} X[c m] @{}|}
     \hline \linespread{0}#2\newline \tiny #1&\linespread{0}#4 \newline\tiny #3  \\\hline
     \end{tabu}}

\newcommand \testA [4]{%
    \begin{tabu} to \hintscolumnwidth {@{}|X[-1,m,c]|@{--}X[-1,m, c]|@{}}  %spread 2cm
        \hline      {#2 } & #4 \\ \tiny #1 & \tiny #3\\ \hline 
    \end{tabu}}

\def \dateA [#1.#2-#3.#4]{ \testA{\monthname[#1]} {#2}  {\monthname[#3]}  {#4} }
\def \dateB [#1.#2-#3.#4]{ \testB{\monthname[#1]} {#2}  {\monthname[#3]}  {#4} }
\def \dateBb [#1.#2-#3.#4]{ \testBb{\monthname[#1]} {#2}  {\monthname[#3]}  {#4} }

\begin{document}%
\ \\
\dateA[09.2008-09.2012]\ \\
\dateB[09.2008-09.2012]\ \\
\dateBb[09.2008-09.2012]\ \\
2008--2012
\end{document}

Produces the following result:
Result

Any suggestions how to make it even more beautiful are welcome.

Update: I took one step back and solved it by just using boxes. My problem with them is that I have to replace \ by \newline if want to use them in the existing tabu cells. This messes up line spacing, e.g.

\documentclass{article}
\usepackage{tabu,xcolor}
\usepackage[ngerman]{babel}
\usepackage{datetime}

\newcommand* \datumsZellenBreite {11mm}
\newcommand* \datumsZifferMonatsAbstand{-0.8mm}
\newcommand \zeitspanneA[4]{%same as B, but uses \newline instead of \\ for linebreak
    {\parbox{\datumsZellenBreite}{\centering{#2%
    %\\%
    \newline
    \vspace{-2.8mm}\tiny #1}}}\hspace{\datumsZifferMonatsAbstand}{\raisebox{0.4mm}{\color{blue}$\rightarrow$}}\hspace{\datumsZifferMonatsAbstand}{\parbox{\datumsZellenBreite}{\centering{#4%
    %\\%
    \newline
    \vspace{-2.8mm}\tiny #3}}}
}
\def \zeitA [#1.#2-#3.#4]{ \zeitspanneA{\monthname[#1]} {#2}  {\monthname[#3]}  {#4} }

\newcommand \zeitspanneB[4]{
    {{\parbox{\datumsZellenBreite}{\centering{#2\\\vspace{-2.8mm}\tiny #1}}}\hspace{\datumsZifferMonatsAbstand}{\raisebox{0.4mm}{\color{blue}$\rightarrow$}}\hspace{\datumsZifferMonatsAbstand}{\parbox{\datumsZellenBreite}{\centering{#4\\\vspace{-2.8mm}\tiny #3}}}}
}
\def \zeitB [#1.#2-#3.#4]{ \zeitspanneB{\monthname[#1]} {#2}  {\monthname[#3]}  {#4} }

\begin{document}%
A should look like B, so it can be used inside tabu.\\ \ \\
\zeitB[09.2008-09.2012]\ B\\ \\
\zeitA[09.2008-09.2012]\ A\\ \\

\begin{tabu}{XX}
a & \zeitA[09.2008-09.2012] %can't use B here
\end{tabu}

\end{document}

Results in boxExample

Update2: I'm now pretty close to what I desire. Actually the \baselineskip=-valA\newline\par\vspace{-valA} to get the year-month spacing right seems like voodoo to me, but I should sacrifice a goat for finding it. The only thing that's undesired is that A doesn't start at the same baseline as the digits do.

\documentclass{article}
\usepackage{tabu,xcolor}
\usepackage[ngerman]{babel}
\usepackage{datetime}

\setlength\fboxsep{0pt}
\newcommand* \datumsZellenBreite {10.5mm}
\newcommand* \datumsZifferMonatsAbstand{-2.8mm}
\newcommand \zeitspanne[4]{%same as B, but uses \newline instead of \\ for linebreak
    {\parbox{\datumsZellenBreite}{\centering{#2\baselineskip=\datumsZifferMonatsAbstand\newline\par\vspace{\datumsZifferMonatsAbstand}\tiny{\strut#1}}}}\hspace{-0.6mm}{\raisebox{0.35mm}{\color{blue}--}}\hspace{-0.2mm}%
    {\parbox{\datumsZellenBreite}{\centering{#4\baselineskip=\datumsZifferMonatsAbstand\newline\par\vspace{\datumsZifferMonatsAbstand}\tiny{\strut#3}}}}%
}
\def \zeit[#1.#2-#3.#4]{\zeitspanne{\monthname[#1]}{#2}{\monthname[#3]}{#4}}

\begin{document}%
\begin{tabu}{@{}X[-1]@{}|X@{}}
\hline%
A & \zeit[09.2008-09.2012]
\\\hline
\end{tabu}
\end{document}

Produces:

Datum3

Any ideas how I can fix this?

share|improve this question
    
tabu might not be a good choice for a document that will continue to evolve. The author of the package is revising it and promising that there will not be backwards compatibility; see here. –  jon Apr 17 '13 at 18:12
1  
Have you seen moderntimeline? –  doncherry Apr 17 '13 at 18:12
    
I thought tabu is the newest table package and thus the first choice. I've now taken a look at moderntimeline, it looks nice, but it's not what I want. –  Stefan K. Apr 17 '13 at 19:27
    
I think that after the edit, I don't understand what you are trying to achieve. Don't the two possibilities I suggested in my answer give you (after changing the en-dash for the colored arrow) the result you are looking for? If not, could you please explain what are they lacking to achieve your layout? –  Gonzalo Medina Apr 19 '13 at 20:03
    
your suggested answer came pretty close. I just wanted to improve the year-month spacing, reduce the borders, adjust the dash to the middle and use it inside existing tabu cells. I'm probably going to accept your answer as soon as I have the desired result. –  Stefan K. Apr 21 '13 at 18:30
show 2 more comments

2 Answers

up vote 4 down vote accepted

Perhaps something like this? I used tabularx instead of tabu. The vertical alignment for the tabularx was set to [t], and \firsthline (from the array package) was used:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{array}
\usepackage{tabularx}
\usepackage{datetime}

\newcolumntype{Y}{>{\small\centering\arraybackslash}X}

\newcommand*\hintscolumnwidth{0.2\textwidth} % best: 0.175\textwidth

\def\dateS[#1.#2-#3.#4]{\testS{\monthname[#1]}{#2}{\monthname[#3]}{#4}}

\newcommand\testS[4]{%
{\renewcommand\arraystretch{0.8}
\begin{tabularx}{\hintscolumnwidth}[t]{|@{}Y@{}c@{}Y@{}|}
\firsthline
#2 &\multicolumn{1}{@{}c@{}}{--} & #4 \\[-1ex]
\tiny#1 && \tiny#3 \\
\hline
\end{tabularx}}}

\begin{document}%

\dateS[09.2008-12.2012] Some text\par
\dateS[01.1997-09.2012] Some text\par
\dateS[09.2000-09.2012] Some text

\end{document}

enter image description here

And using boxes (minipages and \parboxes, in this case), one doesn't need any additional package:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{datetime}

\newlength\mylen
\settowidth\mylen{--}
\newlength\hintscolumnwidth
\setlength\hintscolumnwidth{0.2\textwidth} % best: 0.175\textwidth

\def\dateS[#1.#2-#3.#4]{\testS{\monthname[#1]}{#2}{\monthname[#3]}{#4}}

\newcommand\testS[4]{%
{\setlength\fboxsep{0pt}%
\fbox{\begin{minipage}[t]{\hintscolumnwidth}
\parbox[t]{0.5\hintscolumnwidth}{\centering%
\raggedright%
\makebox[0pt][l]{\hspace*{\dimexpr0.5\hintscolumnwidth-2\mylen\relax}--}%
\centering#2\\ \tiny#1
}%
\parbox[t]{0.5\hintscolumnwidth}{\centering%
#4\\ \tiny#3
}%
\end{minipage}}}}

\begin{document}%

\dateS[09.2008-12.2012] Some text\par
\dateS[01.1997-09.2012] Some text\par
\dateS[09.2000-09.2012] Some text

\end{document}

enter image description here

share|improve this answer
add comment

glyj from #latex suggested another using tikz:

\documentclass{article}
\usepackage{tabu,xcolor}
\usepackage[ngerman]{babel}
\usepackage{datetime}
\usepackage{tikz} 

\setlength\fboxsep{0pt}
\newcommand* \datumsZellenBreite {10.5mm}
\newcommand* \datumsZifferMonatsAbstand{-2.8mm}
\newcommand \zeitspanne[4]{
        {\parbox{\datumsZellenBreite}{\centering{#2\baselineskip=\datumsZifferMonatsAbstand\newline\par\vspace{\datumsZifferMonatsAbstand}\tiny{\strut#1}}}}\hspace{-0.6mm}{\raisebox{0.35mm}{\color{blue}--}}\hspace{-0.2mm}%
        {\parbox{\datumsZellenBreite}{\centering{#4\baselineskip=\datumsZifferMonatsAbstand\newline\par\vspace{\datumsZifferMonatsAbstand}\tiny{\strut#3}}}}%
}
\def \zeit[#1.#2-#3.#4]{\zeitspanne{\monthname[#1]}{\ #2}{\monthname[#3]}{\ #4}}

\begin{document}%

\begin{tikzpicture}
  \useasboundingbox (0cm,0cm) rectangle (\textwidth,1cm);
  \coordinate (A) at (0,0);
  \coordinate (B) at (\textwidth,0);
  \coordinate (I) at (0.5,0);
  \coordinate (J) at (0.5,1);
  \coordinate (Zeitpos) at (1,0.5);
  \coordinate (C) at (0,1);
  \coordinate (D) at (\textwidth,1);

  \draw  (0,0.6) node {A};
  \draw (A)--(B);
  \draw (C)--(D);
  \draw (Zeitpos) node [right] {\zeit[09.2008-03.2012]};
  \draw (I)--(J);      
\end{tikzpicture}

\vspace{2cm}

\begin{tabu}{@{}X[-1]@{}|X@{}}
\hline%
A & \zeit[09.2008-03.2012]
\\\hline
\end{tabu}
\end{document}
share|improve this answer
add comment

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.