5

I need to produce 50 playing cards (60x90mm) with a template available in PSD or PNG or anything else (see picture below).

Here is what I tried:

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm]{geometry}
\usepackage{graphicx}

\newcommand{\card}{ \centerline{\includegraphics{background.png}} % Why isn't it locked on top-left corner % of the page ? (it should) % How to insert the text here, vertically + horizontally centered over the background? \newpage }

\begin{document} \card{This is card 1.} \card{Hello mister polynomial $x^2+1$.}

\end{document}

Questions:

  1. What file format to use for the background template? Would you use PNG? (Goal: I'm producing a PDF that will go to the print worker.)

  2. Why doesn't the previous solution overwrite the text over the background? (this is what should happen)?

enter image description here


Bad output (with previous code):

enter image description here

Basj
  • 764
  • 1
    png is a pixel format, at that limited size of your card however you won't see much issues from pixel. –  Feb 22 '17 at 15:44
  • @ChristianHupfer I've included a non-working example, do you see what's wrong? – Basj Feb 22 '17 at 15:51
  • Is this alternative relevant?? http://tex.stackexchange.com/questions/354342/flacards-package-renewcommand-with-variables – Steven B. Segletes Feb 22 '17 at 15:57
  • @StevenB.Segletes I modified the question to be more specific and to show where my current code fails. – Basj Feb 22 '17 at 15:58
  • maybe http://tex.stackexchange.com/questions/207929/how-to-draw-the-cards-of-a-deck could be of interests – samcarter_is_at_topanswers.xyz Feb 22 '17 at 16:07
  • @samcarter and StevenBSegletes I'd like to do it without any 3rd party package. Now the only problems I'm facing (see my code) are: 1) how to have the PNG inserted on top-left corner (no margin) 2) how to make the text \card{this is the text} displayed centered horizontally / vertically over the background png. – Basj Feb 22 '17 at 16:09

4 Answers4

11

Update at the end -- give it a try

The background image can be done with tcolorbox and using many of its options, putting it in the background. See the applications of the options how the image is changed.

Considering the dimensions: Please take into account the cutting by your printer, so the margins should be larger, most likely!

\documentclass{article}

\usepackage[paperwidth=50mm,paperheight=90mm,margin=0pt,nohead,nofoot]{geometry}

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

\newtcolorbox[auto counter]{cardbox}[1][]{enhanced,nobeforeafter,after={\clearpage},width=50mm,height=90mm,halign=center, valign=center, title={This is card \thetcbcounter},colback={white!70!yellow},colbacktitle={cyan},coltitle={black},overlay={%
    \begin{tcbclipinterior}
    \node[opacity=0.2] (A) at (interior.center) {\includegraphics[width=5cm,height=9cm]{ente}};
    \end{tcbclipinterior}
  },#1}

\parindent=0pt

\newcommand{\card}[2][]{%
  \begin{cardbox}[#1]
    #2%
  \end{cardbox}%
}
\begin{document}
\pagestyle{empty}

\card{Hello Darkness my old friend}

\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}

\end{document}

enter image description here

enter image description here

\documentclass{article}

\usepackage[paperwidth=150mm,paperheight=270mm,margin=0pt,nohead,nofoot]{geometry}



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

\tcbset{cardsboxstyle/.style={%
    left skip=0em,
    right skip=0em,
    width=50mm,
    height=90mm,
    halign=center, 
    valign=center,
    title={This is card \thetcbcounter},
    left=0pt,
    right=0pt,
    top=0pt,
    bottom=0pt,
    colback={white!70!yellow},
    colbacktitle={cyan},
    coltitle={black}
  },
  backgroundimage/.style={%
    overlay={%
    \begin{tcbclipinterior}
    \node[opacity=0.1] (A) at (interior.center) {\includegraphics[width=5cm,height=9cm]{ente}};
    \end{tcbclipinterior}
    }
  }
}


\newtcolorbox[auto counter]{cardbox}[1][]{enhanced,nobeforeafter,cardsboxstyle,backgroundimage,#1}

\parindent=0em

\newcommand{\card}[2][]{%
  \begin{cardbox}[#1]
    #2%
  \end{cardbox}%
}
\begin{document}
\pagestyle{empty}


\begin{tcbraster}[raster columns=3,raster column skip=0pt,raster row skip=0pt,raster width=150mm,raster equal height,raster left skip=0pt,raster right skip=0pt]
\card{Hello Duckness my old friend}
\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}
\card{Hello Cuteness my old friend}
\card[colbacktitle={red},overlay={\draw[opacity=0.2,step=1cm,help lines,blue] (interior.north east) grid (interior.south west);}]{Hello Cuteness my old friend}
\card{Hello Duckness my old friend}
\card[fontupper=\huge]{Hello Mr. Polynomial $x^{2} + x = 1$}
\card{Hello Cuteness my old friend}
\card{Hello Duckness my old friend}
\card[colupper={blue},ams align]{E=mc^{2}}
\end{tcbraster}

\end{document}

enter image description here

5

Maybe something like this??

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=.1pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}

\newcommand{\card}[1]{\def\stacktype{L}%
\stackon[-.35\paperheight]{%
\raisebox{-.94\paperheight}{\includegraphics[width=1\paperwidth,height=.2\paperheight]{%
  example-image}}%
}{\Centerstack{#1}}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}

enter image description here

FOLLOW UP (to answer OP's question below)

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=.1pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}

\newcommand{\card}[1]{\def\stacktype{L}%
\stackon[-.45\paperheight]{%
\raisebox{-.94\paperheight}{\includegraphics[width=1\paperwidth,height=\paperheight]{%
  example-image}}%
}{\Centerstack{#1}}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}

enter image description here

Note that the .94\paperheight image shift is, essentially, \dimexpr-\paperheight+\baselineskip\relax

P.S.

The following code can supercede both of the above examples, allowing the image height to be independently specified in the \def of \imgheight.

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=0pt]{geometry}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}
\def\imgheight{1.0\paperheight}% <---THIS SETS HOW MUCH OF THE CARD THE IMAGE TAKES UP
\newcommand{\card}[1]{\def\stacktype{L}%
\raisebox{\dimexpr-\paperheight+.85\baselineskip\relax}{%
\stackinset{c}{}{c}{\dimexpr.5\paperheight-.5\dimexpr\imgheight\relax}{%
  \Centerstack{#1}}{\includegraphics[width=\paperwidth,height=\imgheight]{example-image}}%
}%
\newpage%
}
\parindent 0pt
\begin{document}
\card{hello}
\card{hello2\\this is a test\\of my method}
\end{document}
  • Thanks Steven! The only little remaining thing is that the image should take the whole 6x9cm space, and the text should be over (on top) of the image. – Basj Feb 22 '17 at 16:12
  • @Basj See FOLLOW UP – Steven B. Segletes Feb 22 '17 at 16:14
  • Thanks a lot @StevenBSegletes, it works. Last question: would you see a version without any 3rd party packages? (Just for LaTeX learning purposes). This works for the vertical+horizontal centering : \newcommand{\card}[1]{ \topskip0pt \vspace*{\fill} \begin{center} #1 \end{center} \vspace*{\fill} \newpage } but how to insert the PNG image as background? Is there a way to move the cursor at the top of the page to do then \centerline{\includegraphics{background.png}} ? – Basj Feb 23 '17 at 01:50
  • @Basj Well, since I wrote stackengine, does that make it a 1st-party package?? :^) I figure you already have geometry and graphic... – Steven B. Segletes Feb 23 '17 at 02:04
  • Haha right ;) I was trying with this (rput), but it doesn't work: \newcommand{\card}[1]{ \rput(0,0){\includegraphics{background.png}} \topskip0pt \vspace*{\fill} \begin{center} #1 \end{center} \vspace*{\fill} \newpage. The vertical/horiz alignement of text works, the image is displayed, but unfortunately not at the top left corner... – Basj Feb 23 '17 at 02:07
  • @Basj Maybe try a \noindent before invoking \card. – Steven B. Segletes Feb 23 '17 at 02:12
  • This seems to work now: http://tex.stackexchange.com/a/355272/27733 – Basj Feb 23 '17 at 02:14
4

An eso-pic solution:

\documentclass{minimal}
\usepackage[paperheight=6cm,paperwidth=9cm]{geometry}
\usepackage{graphicx}

\usepackage{eso-pic}

\AddToShipoutPictureBG{\includegraphics[height=6cm,width=9cm]{example-grid-100x100bp}}

\newcommand{\card}[1]{%
\begin{minipage}[c][\textheight][c]{\textwidth}%
\centering%
#1
\end{minipage}
}

\begin{document}
\noindent
\color{white}
\card{test}%
\card{bla}%
\end{document}

enter image description here

1

By combining what I've learned thanks to the good answers here and this answer about image background, this finally works (without any 3rd-party package):

\documentclass{minimal}
\usepackage[english]{babel}
\usepackage[paperheight=6cm,paperwidth=9cm,margin=0pt]{geometry}
\usepackage{graphicx}

\newcommand{\card}[1]{
\noindent
\makebox[0pt][l]{\raisebox{-\totalheight}[0pt][0pt]{\includegraphics{background.png}}}
\topskip0pt
\vspace*{\fill}
\begin{center}#1\end{center}
\vspace*{\fill}
\newpage
}

\begin{document}
\card{This is card 3.}
\card{Hello mister polynomial $x^2+1$\\You too}
\end{document}
Basj
  • 764
  • If anyone sees even simpler than makebox, raisebox, topskip, I'm interested to learn an even more simple solution! – Basj Feb 23 '17 at 02:20