Skip to content

Commit

Permalink
Added new environments Cell and Row.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzl committed Jan 16, 2014
1 parent 847e5be commit 87d2de2
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 11 deletions.
56 changes: 47 additions & 9 deletions grid-system-test.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,57 @@
\usepackage[default,scale=0.95]{opensans}
\usepackage[scaled=0.85]{beramono}

\usepackage{showframe}
\usepackage{grid-system}

\setlength{\parindent}{0cm}
%\setlength{\parindent}{0cm}

\begin{document}
\begin{document}%

\begin{row}[cellsep=0.5cm]{3}{3}
\begin{cell}{1}
\end{cell}
\begin{cell}{1}
\end{cell}
\begin{cell}{1}
\end{cell}
\begin{Row}%
\begin{Cell}{2}
This is a test for Cell and Row, with a text slightly longer than the row.
\end{Cell}
\begin{Cell}{1}
And this is another text spanning many, rows, more than one. Lorem isum sit dolor amet.
\end{Cell}
\end{Row}

\bigskip

\begin{Row}%
\begin{Cell}{2}
This is a test for Cell and Row, with a text slightly longer than the row.
\end{Cell}%
\begin{Cell}{1}
And this is another text spanning many, rows, more than one. Lorem isum sit dolor amet.
\end{Cell}%
\end{Row}

\bigskip

\begin{row}[cellsep=0.5cm]{3}{3}%
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\end{row}

\begin{row}[cellsep=0.5cm]{3}{3}%
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\begin{cell}{1}
This is a nice text, longer than one row.
\end{cell}
\end{row}

\bigskip
Expand Down
42 changes: 42 additions & 0 deletions grid-system.sty
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
\RequirePackage{calc}
\RequirePackage{xkeyval}
\RequirePackage{ifthen}
\RequirePackage{environ,forloop}

\newcommand{\gridsystem@cellwidth}[2]{#1\linewidth/#2}

Expand Down Expand Up @@ -43,3 +44,44 @@
}{
\gridsystem@finishrow%
}

\NewEnviron{Cell}[1]{%
%\global\@namedef{gridsystem@cellcontent\arabic{gridsystem@cellcount}}{\BODY}%
\edef\@celltemp{\BODY}%
%\global\@namedef{gridsystem@cellcontent\arabic{gridsystem@cellcount}}{\@celltemp}%
\expandafter\global\expandafter\edef\csname gridsystem@cellcontent\arabic{gridsystem@cellcount}\endcsname{\@celltemp}%
\global\@namedef{gridsystem@cellwidth\arabic{gridsystem@cellcount}}{#1}%
\stepcounter{gridsystem@cellcount}%
\addtocounter{gridsystem@stripecount}{#1}%
}

%%%%
%%%% equivalent of \@namedef for counters?
%%%%

\newcounter{gridsystem@cellcount}
\newcounter{gridsystem@stripecount}

\newenvironment{Row}[1][cellsep=1.75em]{%
\setkeys{row}{#1}%
\setcounter{gridsystem@cellinrow}{0}%
\setcounter{gridsystem@stripecount}{0}%
\noindent%
}{%
\setlength{\gridsystem@one@cellwidth}{(\linewidth-\gridsystem@cellsep*(\value{gridsystem@cellcount}-1))/\value{gridsystem@stripecount}}%
% For each 1..gridsystem@cellcount
\forloop{gridsystem@cellinrow}{0}{\value{gridsystem@cellinrow} < \value{gridsystem@cellcount}}{%
\expandafter\begin{minipage}[t]{\dimexpr\@nameuse{gridsystem@cellwidth\arabic{gridsystem@cellinrow}}\gridsystem@one@cellwidth\relax}%
\@nameuse{gridsystem@cellcontent\arabic{gridsystem@cellinrow}}%
\end{minipage}%
\@ignoretrue% Ignore spaces
\ifthenelse{\value{gridsystem@cellinrow}<\value{gridsystem@cellcount}}{%
\gridsystem@finishcell%
}{%
\gridsystem@finishlastcell%
}%
}%
\setcounter{gridsystem@cellcount}{0}%
\setcounter{gridsystem@stripecount}{0}%
%\gridsystem@finishrow%
}
60 changes: 58 additions & 2 deletions grid-system.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

\usepackage[default,scale=0.95]{opensans}
\usepackage[scaled=0.85]{beramono}
%\usepackage[default,semibold]{sourcecodepro}
%\usepackage[default,semibold]{sourcesanspro}


\usepackage{listings}
\usepackage{grid-system}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{grid-system}
Expand All @@ -29,6 +32,8 @@
\title{Grid System}
\author{Marcus Bitzl\\ \url{[email protected]}}

\renewcommand{\emph}[1]{\textcolor{red!65!black}{#1}}

\begin{document}
\maketitle

Expand All @@ -37,12 +42,39 @@
\end{abstract}

\section{Usage}
There are two environments to divide your area into boxes: \texttt{row} to divide your area into columns and \texttt{cell} to fill the area with content:
\subsection{Overview}
There are two methods to divide your row into multiple columns. The first one with uppercase \emph{Cell} and \emph{Row} is easier to use as it collects the content of the cells and calculates everything for you. As a result, it might break on certain contents (e.g. footnotes). For such cases, the second method with lowercase \emph{row} and \emph{cell} will work. These are more capable, but need more configuration.

\medskip

\subsection{The simple way}
\minisec{Example:}
\begin{lstlisting}
\begin{Row}%
\begin{Cell}{2}
This is a long row spanning two thirds of the text width. This one cannot have footnotes.
\end{Cell}
\begin{Cell}{1}
This is a long row spanning one third of the text width.
\end{Cell}
\end{Row}
\end{lstlisting}

\minisec{Output:}
\begin{Row}%
\begin{Cell}{2}
This is a long row spanning two thirds of the text width. This one cannot have footnotes.
\end{Cell}
\begin{Cell}{1}
This is a long row spanning one third of the text width.
\end{Cell}
\end{Row}

\clearpage

\subsection{The complete way}
\begin{lstlisting}
\begin{row}{<Number of columns}{<Number of cells>}
\begin{row}{<Total number of columns}{<Number of cells>}%
\begin{cell}{<Number of columns to span>}
...
\end{cell}
Expand All @@ -52,6 +84,30 @@ \section{Usage}
\end{row}
\end{lstlisting}

\minisec{Example:}
\begin{lstlisting}
\begin{row}{3}{2}%
\begin{cell}{2}
...
\end{cell}
\begin{cell}{1}
...
\end{cell}
\end{row}
\end{lstlisting}

\minisec{Output:}
\begin{row}{3}{2}%
\begin{cell}{2}
This is a long row spanning two thirds of the text width\footnote{Yes, really!}, telling your nothing\footnote{But it has footnotes, yeah!}.
\end{cell}
\begin{cell}{1}
This is a long row spanning one third of the text width.
\end{cell}
\end{row}

\bigskip

Each cell is created using a \texttt{minipage} environment. In future versions the will be a switch to choose either minipages or parboxes.

\section{Parameters}
Expand Down

0 comments on commit 87d2de2

Please sign in to comment.