# What is the best way to setup this statblock as a macro?

I'd like to get a macro setup for this statblock format. Basically, I will be converting an XML document containing the data for the instances within the document.

This is a sample of the format I am looking for:

-
Perhaps an example of what you get as input would be helpful as well. If possible example input matching your example output. –  Roelof Spijker Oct 13 '11 at 14:15
Welcome to TeX.sx! Please make sure that all images are uploaded using the official stackexchange interface, i.e. the image icon on top of the text field (shortcut: CTRL+G). This ensures that all images are always accessible and do not expire. As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  Martin Scharrer Oct 13 '11 at 14:16
-1: Please don't ask "How do I achieve this layout", but rather a question about a specific feature that you're struggling with, one problem per question. This way other users who have a similar problem can benefit from your question and the solutions to it (No one's gonna ask for the same layout as you). It's no problem to ask several questions, if you've made some attempt yourself first. It's enormously helpful to see what you've tried so far to figure out what doesn't work. After all, the point of this Q&A site is to solve specific problems, not to have other people do your work. –  doncherry Oct 13 '11 at 14:45
doncherry, I've found one of the biggest issues while learning tex is the lack of real world examples. And, while specific layouts will not be useful in a copy and paste way, they are helpful for establishing answers to "how would I even approach something like this" questions. –  Jeffrey Fuller Oct 13 '11 at 15:16
You can use a colored table with colortbl package. The tabular has only one column of p{\linewidth} column type. –  Leo Liu Oct 13 '11 at 16:00

Does the following look like what you want?

\documentclass{article}

\usepackage{times}      % change font
\usepackage{xcolor}     % colours
\usepackage{colortbl}   % colour table
\usepackage{amssymb}    % symbols
\usepackage{epsdice}    % dice

% define my own colours
\definecolor{darkgreen}{rgb}{0.25, 0.30, 0.15}
\definecolor{lightgray}{rgb}{0.9,0.9,0.9}
\definecolor{darkgray}{rgb}{0.75,0.75,0.75}

\begin{document}

\begin{tabular}{p{\linewidth}}
\rowcolor{darkgreen}\color{white}\bfseries Impersonator Mimic \hfill Level 16 Controller \\
\rowcolor{darkgreen}\color{white} Medium aberrant magical beast    \hfill XP 1,400\\
\rowcolor{lightgray}\textbf{HP} 160; \textbf{Bloodied} 80 Initiative +14\\
\rowcolor{lightgray} \textbf{AC} 30, \textbf{Fortitude} 27, \textbf{Reflex} 28, \textbf{Will} 27 \textbf{Perception} +13\\
\rowcolor{lightgray} \textbf{Speed} 6 Darkvision, tremorsense 5\\
\rowcolor{lightgray} \textbf{Resist} 10 acid\\
\rowcolor{darkgreen}\color{white}\textbf{Standard Actions}\\
\rowcolor{darkgray} \textbf{Slam $\blacklozenge$ At-Will}\\
\rowcolor{lightgray} \emph{Attack:} Melee 2 (one creature); +21 vs. AC\\
\rowcolor{lightgray} \emph{Hit:} 3d8 +11 damage.\\
\rowcolor{darkgray} \textbf{Forcible Conversion} (charm) $\blacklozenge$ \textbf{Recharge} \epsdice{5} \epsdice{6}\\
\end{tabular}

\end{document}


EDIT

Following the comments, here is an update that should help to 'separate content from style'.

\documentclass{article}

\usepackage{times}      % change font
\usepackage{xcolor}     % colours
\usepackage{colortbl}   % colour table
\usepackage{amssymb}    % symbols
\usepackage{epsdice}    % dice

% define my own colours
\definecolor{darkgreen}{rgb}{0.25, 0.30, 0.15}
\definecolor{lightgray}{rgb}{0.9,0.9,0.9}
\definecolor{darkgray}{rgb}{0.75,0.75,0.75}

\newcommand{\printstattable}{%
\begin{tabular}{p{\linewidth}}
\rowcolor{darkgreen}\color{white}\bfseries \name \hfill \level \\
\rowcolor{darkgreen}\color{white} \creaturedescription    \hfill XP \experience\\
\rowcolor{lightgray}\textbf{HP} \hp; \textbf{Bloodied} \bloodied\, Initiative \initiative\\
\end{tabular}
}

\newcommand{\setbasicstats}[4]{%
\def\name{#1}%
\def\creaturedescription{#2}%
\def\level{#3}%
\def\experience{#4}}

\begin{document}

\setbasicstats{Impersonator Mimic}{Medium abberrant magical beast}{Level 16 Controller}{1,400}
\def\hp{160}
\def\bloodied{80}
\def\initiative{+14}
\printstattable

\vspace{2cm}
\setbasicstats{Fantasy creature}{Something else}{Level 1 rogue}{2,100}
\def\hp{20}
\def\bloodied{13}
\def\initiative{-230}
\printstattable

\end{document}


You'll notice that I have demonstrated 2 separate approaches

1. \setbasicstats takes 4 arguments and does the \def for you
2. The \hp, \bloodied, \initiative have been done manually, but there's no reason that you couldn't put them in another \newcommand

If you like this approach, you just need to complete the \printstattable command with the other rows, and define newcommands to fill-in the remaining entries.

-
That is the basic structure, yes. I guess what I am asking is, should I be doing that full markup for every stat block. Or, create a macro/function that I just pass the data bits to as parameters? The basic format will always be the same, but the data will be different in each instance. I need to do a better write up with examples I think. –  Jeffrey Fuller Oct 13 '11 at 17:42
@JeffreyFuller It looks like there are quite a few 'data bits' to pass to your command. I think that \newcommand can take at most 9 arguments, although it can be overcome tex.ac.uk/cgi-bin/texfaq2html?label=moren9 –  cmhughes Oct 13 '11 at 17:53
@JeffreyFuller Yes, that would be really good. In fact, many people here are able to create small miracles with Tex but only if they have a concrete problem to deal with. That's why you receive the comments to your question. Can you tell us which part is troubling you the most and what feels like doable ? –  percusse Oct 13 '11 at 17:56
@JeffreyFuller I've updated my solution- I hope this is closer to what you want. –  cmhughes Oct 13 '11 at 18:49