I'm trying to recreate a table from a RPG character sheet:
I don't care about the colouring particularly, black and white works perfectly fine, the sizing is the main issue. I am going to be making multiple copies of this table, and I want all of them to be uniform. So even if every data value was blank is would then just produce a blank table of the same measurements as a filled in version.
I'm wanting each box to have (roughly) the following widths (relative to the total table width):
- Name:70%, Class: 30%
- Range: 21%, RoF: 37%, Damage: 40%
- Pen: 21%, Clip 18%, Reload: 18%, Weight: 14%, Availability: 19%
- Special: 100%
Sketch with measurements in place of the data for the table (not drawn to scale):
These widths are to keep the table looking close to the original as possible in terms of layout. Being still relatively new to LaTeX and very new to doing more than a basic data table. The only way I could think of doing this would be something along the lines of making 100 columns, and using \multicolumn{% above}
. However even with that lengthy method, since LaTeX likes to make everything as small as possible the far right columns wouldn't have their full width and it would create different sized tables depending on the data.
I've looked around as quite a number of questions about fixed length table columns but all seem to be fixing it to be smaller than the text within (causing multine) rather than wanting to keep the size the same and allow empty space to fill the gap.
For some context, the goal is to have a macro that I can input the data for each box, and then the macro creates a copy of the table, filled in with the entered data. The macro I have sorted, the issue is just the formatting/layout of the table.
Here is the macro code I have:
\documentclass[11pt]{article}
\usepackage{fancyhdr}
\oddsidemargin 0.2cm
\topmargin -1.0cm
\textheight 24.0cm
\textwidth 15.25cm
\parindent=0pt
\parskip 1ex
\pagestyle{fancy}
\newcommand{\printweptable}{
\begin{tabular}{p{\linewidth}}
Name: \name \hfill Cls: \class \\
Rng: \range \hfill RoF: \rof \hfill Rmg: \dmg\\
Pen: \pen \hfill Clip: \clip \hfill Rld: \rld \hfill Wt: \wt \hfill Avl: \avl\\
Special: \special
\end{tabular}
}
%Weapon info
\newcommand{\setwepstats}[9]{%
\def\name{#1}%
\def\class{#2}%
\def\range{#3}%
\def\rof{#4}%
\def\dmg{#5}%
\def\pen{#6}%
\def\clip{#7}%
\def\rld{#8}%
\def\wt{#9}
\wepstatsrelay
}%
\def\wepstatsrelay#1#2{
\def\avl{#1}%
\def\special{#2}}%
\begin{document}
\setwepstats{Name}{Class}{Range}{RoF}{Damage}{Pen}{Clip}{Reload}{Wt}{Availability}{Special}
\printweptable
\setwepstats{}{}{}{}{}{}{}{}{}{}{}
\printweptable
\end{document}
I think I shall use the code provided by Werner, and scrap the macro I had (his seems cleaner to use and reuse.
I have now merged the codes provided by both Werner and cfr and have this working code:
\documentclass{article}
\usepackage{xkeyval}
\makeatletter
\define@cmdkey{rpg}[char@]{name}[]{}
\define@cmdkey{rpg}[char@]{class}[]{}
\define@cmdkey{rpg}[char@]{range}[]{}
\define@cmdkey{rpg}[char@]{rof}[]{}
\define@cmdkey{rpg}[char@]{damage}[]{}
\define@cmdkey{rpg}[char@]{pen}[]{}
\define@cmdkey{rpg}[char@]{clip}[]{}
\define@cmdkey{rpg}[char@]{reload}[]{}
\define@cmdkey{rpg}[char@]{weight}[]{}
\define@cmdkey{rpg}[char@]{availability}[]{}
\define@cmdkey{rpg}[char@]{special}[]{}
\define@cmdkey{rpg}[char@]{mods}[]{}
\define@cmdkey{rpg}[char@]{qualities}[]{}
\define@cmdkey{rpg}[char@]{width}[\linewidth]{}
\newcommand{\statlabel}{\textsc}
\usepackage{calc,xparse}
\newlength\mycardwidth
\setlength\mycardwidth{.75\textwidth}
\NewDocumentCommand \boxme { O{} }{%
\fbox{%
\parbox{\linewidth-2\fboxrule-2.5\fboxsep}{\strut #1}%
}%
}
\NewDocumentCommand \pageme { O{} O{} }{%
\begin{minipage}{#1\mycardwidth}
\centering\boxme[#2]
\end{minipage}%
}
\NewDocumentCommand \cardme { O{.75\textwidth} +m }{%
\setlength\mycardwidth{#1-2\fboxrule-2\fboxsep}%
\fbox{%
\begin{minipage}{\mycardwidth}
\centering
#2%
\end{minipage}%
}%
}
\newcommand{\setcharacterstats}[1]{%
\begingroup
\setkeys{rpg}{name,class,range,rof,damage,pen,clip,reload,weight,availability,special,mods,qualities,width,#1}%
\noindent
\centering
\cardme[\textwidth]{%
\pageme[.69][\statlabel{Name}: \char@name]%
\pageme[.31][\statlabel{Cls}: \char@class]
\pageme[.22][\statlabel{Rng}: \hfill \char@range \hfill m]%
\pageme[.38][\statlabel{RoF}: \char@rof]%
\pageme[.4][\statlabel{Dmg}: \char@damage]
\pageme[.22][\statlabel{Pen}: \char@pen]%
\pageme[.19][\statlabel{Clip}: \char@clip]%
\pageme[.19][\statlabel{Rld}: \char@reload]%
\pageme[.18][\statlabel{Wt}: \hfill \char@weight \hfill kg]%
\pageme[.22][\statlabel{Avl}: \char@availability]
\pageme[][\statlabel{Special}: \char@special]%
\pageme[][\statlabel{Mods}: \char@mods]%
\pageme[][\statlabel{Qualities}: \char@qualities]%
}
}
\makeatletter
%-----------------------------------
\begin{document}
\setcharacterstats{
name = Long Las,
class = Basic,
range = 150,
rof = S/-/-,
damage = 1d10+3,
pen = 1,
clip = 40,
reload = Full,
weight = 4.5,
availability = Scarce,
special = Accurate Felling (4) Reliable
}
\end{document}
With that code however, is there a way to center the variable data within the remaining space of the cell? E.g. If I had Carbine as the name, it would make the distance from the : and the C be equal to the distance from the e and the right side of the cell. (Not put it in the center of the entire cell).
I tried to edit the variable within the macro to replace \char@name
with \center{\char@name}
however this threw the variable onto an entirely new line (within the cell) and centered it based on the cell sides alone. If there's no simple way to do this, I'll stick with it being left aligned.
p{}
if you create this as a table. Alternatively, you could just use a series ofminipage
s or boxes, for example.