2

I'm trying to do some cards inspired by Google's material design with LaTeX. However, I ran into a problem.

I can't find a way to get a green bar at the top. [As for the symbols I just haven't bothered yet.] At the moment I'm using TikZ. If there is any better way of doing this, please let me know.

This is what I have at the moment:

What I got at the moment

Code:

\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{color}

\usetikzlibrary{shadows.blur}
\usetikzlibrary{shapes.symbols}

\renewcommand\familydefault{\sfdefault}

\definecolor{unigreen}{RGB}{0, 149, 69}

\newcommand{\materialCards}[5][0]{
    \tikz\node[fill=white,
    draw=gray!30,
    blur shadow={shadow blur steps=3},
    inner xsep = 1em,
    inner ysep = 0,
    align=left,
    text width = .4\textwidth,
    ] {
        \begin{mdframed}[hidealllines=true,backgroundcolor=unigreen]
            \bfseries\large \textcolor{white}{#2 - #3}
        \end{mdframed}
        \normalfont #4\\[0.5em]
        \begin{tabular}{cl}
            Symbol  &   #5\\
            Symbol  &   #1
        \end{tabular}
        \vspace{0.3em}
    };
    \vspace{0.2cm}
}

\begin{document}
\materialCards[Homepage]{1}{Title}{Here will be some kind of description. Just don't mind the text at the moment...}{Address}
\end{document}

This is what I would like to have.

What I would like to have

  • Please don't add "answers" code into your question. The question is supposed to only have the question part. :P – Alenanno Sep 8 '16 at 17:47
4

Here's a version with Tikz. As Ignasi, I assumed the number in the title is supposed to increase with each card, so you can do that automatically with a counter.

Output

enter image description here

Code

\documentclass{article}
\usepackage{tikz}
\usepackage{marvosym,fontawesome} % for the symbols

\definecolor{greencard}{RGB}{0,153,99}

\newcounter{cards}
\setcounter{cards}{1}

\newcommand\materialCards[3][.5\textwidth]{%
\tikz{%
    \node[draw=greencard, fill=greencard, minimum height=8mm, text width=#1, font=\bfseries\sffamily, text=white, align=left] (title) {\arabic{cards}~\textemdash~#2};
    \node[align=left, anchor=north west, text width=#1-2\pgflinewidth, text depth=2cm] (desc) at (title.south west) {#3};
    \node[anchor=north west, minimum size=1cm, font=\Large] (symbol1) at (desc.south west) {\faMapMarker};
    \node[anchor=north west, minimum size=1cm, font=\Large] (symbol2) at (symbol1.south west) {\Mundus};
%
    \node[anchor=west, text width=#1-1cm, minimum height=1cm] (add) at (symbol1.east) {Address};
    \node[anchor=west, text width=#1-1cm, minimum height=1cm] (web) at (symbol2.east) {Website};
    \draw[gray, ultra thin, dashed] (symbol2.south east) -- (symbol1.north east);
    \draw[gray, ultra thin, dashed] (symbol1.south west) -- (add.south east);
    \draw[gray, ultra thin, dashed] (desc.south west) -- (desc.south east);
    \draw[gray, thin] (title.north west) rectangle (web.south east);
}%
\stepcounter{cards}%
\par%
\vspace{\baselineskip}%
}

\begin{document}
\materialCards[8cm]{Title}{Here will be some kind of description. Just don't mind the text at the moment... Here will be some kind of description. Just don't mind the text at the moment....}

\materialCards[8cm]{Another Title}{Here will be some other kind of description. Just don't mind the text at the moment... Here will be some other kind of description. Just don't mind the text at the moment...}
\end{document}
  • Thanks a lot. I added a shadow which was trickier than I thought and if-statements in case there is no website. – PsiSquared Sep 8 '16 at 17:10
  • @PsiSquared Ah sure, no problem. :) – Alenanno Sep 8 '16 at 17:13
  • I ran into another problem and wondered why. Somehow LaTeX wants to put all of my cards on the same page. This leads to only a few being visible and the remainder being lost. I found a workaround with \newline and a blank line between each \materialCards (only one or *\* doesn't work). Can you explain this behavior to me? Thanks! – PsiSquared Sep 8 '16 at 17:49
  • @PsiSquared Uhm, that was probably my bad. In any case, replace the last \vspace... with the edit in my answer. – Alenanno Sep 8 '16 at 17:53
  • Aha, so there is a difference between \vpsace{} and \vspace*{}. I always wondered. Thanks a lot! – PsiSquared Sep 8 '16 at 17:59
1

You can try with tcolorbox. Here you have an starting point.

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{fontawesome}

\newtcolorbox[auto counter]{materialCards}[1]{%
enhanced,
drop shadow,
sharp corners,
colframe=green!60!black,
fonttitle=\bfseries,
boxrule=0pt,
drop shadow,
title={\thetcbcounter - #1},
}

\begin{document}

\begin{materialCards}{Title}
Here ill be som kind of description, Just don't mind the text at the moment \dots
\\[5mm]
\begin{tabular}{cl}
\faMapMarker & Address\\
\faGlobe & Website\\
\end{tabular}
\end{materialCards}

\begin{materialCards}{Another card}
Here ill be som kind of description, Just don't mind the text at the moment \dots
\\[5mm]
\begin{tabular}{cl}
\faMapMarker & Address\\
\faGlobe & Website\\
\end{tabular}
\end{materialCards}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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