Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am looking to get a better way of creating the following table:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[letterpaper,tmargin=2cm,bmargin=2cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{amsmath,amsfonts}
\usepackage{booktabs,array}
\usepackage[dvipsnames,table]{xcolor}
\setlength{\parindent}{0pt}

\begin{document}

\renewcommand{\arraystretch}{1.3}
\makebox[\linewidth]{%
\rowcolors{2}{green!10}{white}
\begin{tabular}{|>{\centering}p{3em}|*{12}{c}|p{3em}<{\centering}|}
\hline
Day of Month & \raisebox{-1.5ex}{Jan.} & \raisebox{-1.5ex}{Feb.} & \raisebox{-1.5ex}{Mar.} & \raisebox{-1.5ex}{Apr.} & \raisebox{-1.5ex}{May} & \raisebox{-1.5ex}{June} & \raisebox{-1.5ex}{July} & \raisebox{-1.5ex}{Aug.} & \raisebox{-1.5ex}{Sept.} & \raisebox{-1.5ex}{Oct.} & \raisebox{-1.5ex}{Nov.} & \raisebox{-1.5ex}{Dec.} & Day of Month%
\\ \hline
1 & 1 & 32 & 60 & 91 & 121 & 152 & 182 & 213 & 244 & 274 & 305 & 335 & 1%
\\ %\hline
2 & 2 & 33 & 61 & 92 & 122 & 153 & 183 & 214 & 245 & 275 & 306 & 336 & 2  %
\\ %\hline
3 & 3 & 34 & 62 & 93 & 123 & 154 & 184 & 215 & 246 & 276 & 307 & 337 & 3 %
\\ %\hline
4 & 4 & 35 & 63 & 94 & 124 & 155 & 185 & 216 & 247 & 277 & 308 & 338 & 4 %
\\ %\hline
5 & 5 & 36 & 64 & 95 & 125 &156 &186 &217 &248 &278 & 309& 339& 5%
\\ \hline
6 & 6 & 37 & 65 & 96 & 126 &157 &187 &218 &249 &279 &310 &340 & 6%
\\ %\hline
7 & 7 & 38 & 66&97 &127 &158 &188 &219 &250 &280 &311 &341 &7 %
\\ %\hline
8 & 8 &39& 67&98 &128 &159 &189 &220 &251 &281 &312 &342 &8 %
\\ %\hline
9 & 9 & 40&68 &99 &129 &160 &190 &221 &252 &282 &313 &343 &9 %
\\ %\hline
10 & 10 & 41&69 &100 &130 &161 &191 &222 &253 &283 &314 &344 &10 %
\\ \hline
11 & 11 & 42&70 &101 &131 &162 &192 &223 &254 &284 &315 &345 &11 %
\\ %\hline
12 & 12 & 43&71 &102 &132 &163 &193 & 224&255 &285 &316 &346 &12 %
\\ %\hline
13 & 13 &44&72 &103 & 133&164 &194 &225 &256 & 286&317 &347 &13 %
\\ %\hline
14 &14 & 45&73 &104 &134 &165 &195 &226 &257 & 287&318 &348 &14 %
\\ %\hline
15 & 15 &46&74 &105 & 135&166 &196 &227 &258 &288 &319 &349 &15 %
\\ \hline
16 & 16 & 47&75 &106 &136 &167 &197 &228 &259 &289 &320 &350 &16 %
\\ %\hline
17 & 17 &48& 76&107 & 137&168 &198 &229 &260 & 290& 321& 351& 17%
\\ %\hline
18 & 18 & 49& 77&108 & 138&169 &199 &230 &261 & 291& 322& 352& 18%
\\ %\hline
19 & 19 & 50& 78&109 & 139&170 &200 &231 &262 & 292& 323& 353& 19%
\\ %\hline
20 & 20 & 51& 79& 110& 140&171 &201 &232 &263 &293 &324 &354 &20 %
\\ \hline
21 & 21 &52& 80& 111& 141&172 &202 &233 &264 &294 & 325&355 & 21%
\\ %\hline
22 &22 & 53& 81& 112& 142& 173&203 &234 &265 & 295& 326& 356& 22%
\\ %\hline
23 &23 & 54& 82& 113& 143& 174&204 &235 &266 & 296& 327& 357& 23%
\\ %\hline
24 &24 & 55& 83& 114& 144& 175&205 &236 &267 & 297& 328& 358& 24%
\\ %\hline
25 &25 & 56& 84& 115& 145& 176&206 &237 &268 & 298& 329& 359& 25%
\\ \hline
26 &26 & 57& 85& 116& 146& 177&207 &238 &269 &299 & 330& 360& 26%
\\ %\hline
27 &27 & 58& 86& 117& 147& 178&208 &239 &270 &300 &331 &361 & 27%
\\ %\hline
28 &28 & 59& 87& 118& 148& 179&209 &240 &271 &301 &332 & 362& 28%
\\ %\hline
29 &29 & \ldots &88 &119 &149 &180 &210 &241 &272 &302 &333 & 363& 29%
\\ %\hline
30 &30 & \ldots &89 &120 &150 &181 &211 &242 &273 &303 &334 & 364& 30%
\\ %\hline
31 &31 & \ldots &90 & \ldots & 151 &\ldots &212 &243 &\ldots &304 &\ldots & 365&31 %
\\ \hline
\end{tabular}
}
\end{document}

With better I mean more mathematical or algorithmic. I know, I know, I know.... its tedious as you can see, but at the time I had no time to rethink a different way of doing it.

share|improve this question
    
not much more you could do is there? You could obviously automate the counting in the first and last column but that's only a small part of the table, the rest of it is not algorithmic but just a table of measured data isn't it? Or does your real data increase by one each row in the same way? p{3em}<{\centering} is a mightily devious trick, not seen that before:-) –  David Carlisle Sep 9 '13 at 21:03
    
@DavidCarlisle I thought so. But i guess your expertise or someone elses will do the trick. Just need some inspiration to see if it can be done or not. –  azetina Sep 9 '13 at 21:05
    
If your actual data just increases by one in each column, you could of course compress the whole table –  David Carlisle Sep 9 '13 at 21:06

1 Answer 1

up vote 4 down vote accepted

something like this perhaps.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[letterpaper,tmargin=2cm,bmargin=2cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{amsmath,amsfonts}
\usepackage{booktabs,array}
\usepackage[dvipsnames,table]{xcolor}
\setlength{\parindent}{0pt}

\begin{document}

\renewcommand{\arraystretch}{1.3}
\makebox[\linewidth]{%
\rowcolors{2}{green!10}{white}
\count7=1


\def\myrow{%
\the\count7 & 0 & 31 & 59 & 90 & 120 & 151 & 181 & 212 & 243 & 273 & 304 & 334 & \the\count7
\ifnum\count7<31
\global\advance\count7 1
\\\myrow
\fi}

\def\mon#1{\multicolumn{1}{c}{\raisebox{-1.5ex}{#1}}}

\begin{tabular}{!{\vrule width2pt}>{\centering}p{3em}!{\vrule width2pt}
*{12}{>{\def\ignorespaces{}\the\numexpr\count7+}c<\relax}|
>{\centering\arraybackslash}p{3em}!{\vrule width2pt}}
\hline
\noalign{\vskip2pt}
Day of Month &
\mon{Jan.}&
\mon{Feb.}&
\mon{Mar.}&
\mon{Apr.}&
\mon{May}&
\mon{June}&
\mon{July}&
\mon{Aug.}&
\mon{Sept.}&
\mon{Oct.}&
\mon{Nov.}&
\mon{Dec.}&
Day of Month%
\\
\hline
\myrow
\end{tabular}
}
\end{document}
share|improve this answer
    
Is the \noalign{\vskip2pt} necessary? IMHO looks better without it. Never seen the ! in the tabular specifer. What does it actually do? –  Yiannis Lazarides Sep 9 '13 at 22:00
    
@YiannisLazarides usual viewer/zoom specific issues with coloured rows the hline was vanishing behind the white panel (same issue why I used !\vrule to drop in a wider vertical rule) ! is an array package addition like @ but does not remove the default tabcolsep space so | is the same as !{\vline} –  David Carlisle Sep 9 '13 at 22:08
    
Thanks! Always something to learn... –  Yiannis Lazarides Sep 9 '13 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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