制作卡片,每张卡片都有 PNG 背景

制作卡片,每张卡片都有 PNG 背景

我需要制作 50 张扑克牌(60x90mm),并使用 PSD 或 PNG 或其他格式的模板(见下图)。

以下是我尝试过的:

\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}

问题:

  1. 背景模板使用什么文件格式?你会使用 PNG 吗?(目标:我正在制作一份 PDF 文件,将发送给印刷工人。)

  2. 为什么以前的解决方案没有覆盖背景上的文本?(这是应该发生的)?

在此处输入图片描述


错误输出(使用之前的代码):

在此处输入图片描述

答案1

最后更新——试试看

背景图像可以通过tcolorbox使用其许多选项来完成,将其置于背景中。请参阅选项的应用程序以了解如何更改图像。

考虑尺寸:请考虑打印机的切割,因此边距应该更大,很有可能!

\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}

在此处输入图片描述

在此处输入图片描述

\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}

在此处输入图片描述

答案2

也许是这样的??

\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}

在此处输入图片描述

跟进(回答下面 OP 的问题)

\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}

在此处输入图片描述

请注意,.94\paperheight图像偏移本质上是\dimexpr-\paperheight+\baselineskip\relax

附言

\def下面的代码可以取代上面的两个例子,允许在中独立指定图像高度\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}

答案3

解决方案eso-pic

\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}

在此处输入图片描述

答案4

通过结合我从这里的好答案中学到的知识和这个答案关于图像背景,这最终有效(无需任何第三方包):

\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}

相关内容