How to make a signature field in LaTeX - latex

When I'm writing my laboratory reports in LaTeX, I recently had to make a signature field on the form.
Trondheim 4.september 2009
______________________ ___________________________
Ivar Nesje Team mate's name
The problem was that I could not find a easy way to do it so after a lot of searching on the net I came up with this simple solution
\newcommand{\doubleSignature}[3]{
\begin{minipage}[c]{\textwidth}
\vspace{2cm}
\makebox[12cm][c]{
#1, \today
}
\vspace{3cm}
\makebox[12cm][c]{
\hfill \makebox[5cm][c] {\hrulefill} \hfill \makebox[5cm][c] {\hrulefill} \hfill
}
\makebox[12cm][c]{
\hfill #2 \hfill #3 \hfill
}
\vspace{1cm}
\end{minipage}
}
This allowed me to type;
\doubleSignature{Trondheim}{Ivar Nesje}{Team mate's name}
To achieve the wanted result. If any of you have another way of doing this, not using the letter document class, I'd be really glad to hear your suggestions.

I think I would work from \rule[<raise>]{<width>}{<thickness>}. Because the reference point is the lower left corner, you probably don't even need the optional raising argument. Something like:
\newcommand{\doublesignature}[3][Ivar Nesje]{%
\parbox{\textwidth}{
\centering #3 \today\\
\vspace{2cm}
\parbox{7cm}{
\centering
\rule{6cm}{1pt}\\
#1
}
\hfill
\parbox{7cm}{
\centering
\rule{6cm}{1pt}\\
#2
}
}
}
I've re-ordered your arguments to make your name optional.

Assuming there aren't additional formatting restrictions, I probably would have used a tabular environment instead of boxes, and I would have used \rule{length}{width} instead of \hrulefill:
\newcommand{\doubleSignature}[3]{
\vspace{2cm}
\begin{center}
#1, \today
\end{center}
\vspace{3cm}
\noindent
\begin{tabular}{lcl}
\rule{5cm}{1pt} & \hspace{2cm} & \rule{5cm}{1pt} \\
#2 & & #3
\end{tabular}
\vspace{1cm}
}

Related

How to wrap LaTex command in new environment

This question has already been answered once (wrap LaTeX command in environment), yet I still struggle to make my own rather simple new environment command work.
What I wanted to do is to convert the following LaTex block, which shows the output of some code, into a command I can reuse.
\fbox{\begin{minipage}{\textwidth}
\texttt{
>> CODE OUTPUT
\end{minipage}}
It is clear that in order to make a new environment command that replicates what I do above, I will have to make use of wrappers. (Because of the \fbox and the \texttt command.)
I would like to do this without having to download yet another package, or going into the secret realms of LaTex with some predefined \dir command that is only there to do the same job twice.
Checking the link from before, it seems that a productive solution is to use \bgroup and \egroup. I would therefore write something like this:
\newenvironment{CodeOutput}
{\fbox\bgroup\begin{minipage}{\textwidth}\texttt\bgroup}
{\egroup\end{minipage}\egroup}
Yet this will still not work. (On Overleaf at least.) It would be great if there was a straightforward way of making commands like these. Thanks for any useful suggestions!
If want to write a command that does what you're after, then the following would work:
\newcommand{\mycmd}[1]{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily #1
\end{minipage}%
}%
}
The idea here works because the <arg>ument supplied to \mycmd{<arg>} is replaced by #1 in its entirety. If you want want to rewrite this as an environment, it's a little more difficult, purely because of \fbox. \fbox is doesn't have an environment-form equivalent the same way \texttt has \ttfamily (which is technically a font switch). There is a quick way around it provided by environ - it allows you to capture the contents of an environment in a macro \BODY:
\usepackage{environ}
\NewEnviron{myenvA}{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily \BODY
\end{minipage}%
}%
}
However, you do have the option by capturing the content of an environment inside a box and then setting the box inside an \fbox:
\newsavebox{\codebox}% To store the content of myenvB
\newenvironment{myenvB}{%
\begin{lrbox}{\codebox}%
\ttfamily\ignorespaces
}{%
\end{lrbox}%
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}%
\end{minipage}}%
}
The following minimal example shows all the above cases:
\documentclass{article}
\usepackage{environ}
\newcommand{\mycmd}[1]{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily #1
\end{minipage}%
}%
}
\NewEnviron{myenvA}{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily \BODY
\end{minipage}%
}%
}
\newsavebox{\codebox}
\newenvironment{myenvB}{%
\begin{lrbox}{\codebox}%
\ttfamily\ignorespaces
}{%
\end{lrbox}%
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}%
\end{minipage}}%
}
\begin{document}
\noindent
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily SoMe CoDe HeRe
\end{minipage}}
\bigskip
\noindent
\mycmd{SoMe CoDe HeRe}
\bigskip
\noindent
\begin{myenvA}
SoMe CoDe HeRe
\end{myenvA}
\bigskip
\begin{lrbox}{\codebox}
\ttfamily SoMe CoDe HeRe
\end{lrbox}
\noindent
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}
\end{minipage}}
\bigskip
\noindent
\begin{myenvB}
SoMe CoDe HeRe
\end{myenvB}
\end{document}

How to Indent text in LaTeX in a custom way

Hi I'm new to LaTeX and I'm having some troubles in write a Use Case Specification using the style in this picture.I've tried using listings but i can't succeed in underlying some words.Anyone can help me?
I made a command so you can easily without much typing make multiple usecases, this is the complete latex code with 1 example, you can modify the command, it takes 5 parameters and you can access them with the #:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\newcommand{\spec}[5]{
\begin{description}
\item[\underline{SpecificaUseCase}] #1 \\
#2
\begin{itemize}[noitemsep,topsep=-8pt]
\item[] \underline{pre}: #3
\item[] \underline{post}: #4
\end{itemize}
\item[\underline{FinalSecifica}] #5 \\
\end{description}
}
\begin{document}
\spec{usecasename}{method}{pre stuff}{post stuff}{final}
\end{document}
The result of this code is somthing like this:

\sbox from inside an environment

I'm trying to save some text inside an environment for later use. The smallest test case I could come up with is this. The saved text in the sbox isn't available after the environment is closed. How can I work around that? Thanks.
\documentclass{article}
\begin{document}
\newsavebox{\somebox}
\begin{itemize}
\item hello1
\item hello1 \sbox{\somebox}{Some text}
\end{itemize}
This should show something, but does not: "\usebox{\somebox}"
\end{document}
What you're running into here is a scoping issue. In (La)TeX, you can introduce scopes with { ... }, \bgroup ... \egroup, or \begingroup ... \endgroup. The former two are roughly the same, as \bgroup and \egroup are defined by \let\bgroup{ and \let\egroup}; the last one is slightly different. But the scoping property is the same: any commands, boxen, etc., created or modified within those scopes are not visible outside. And in LaTeX, all environments \begin{env} ... \end{env} implicitly wrap their contents in \begingroup ... \endgroup. This means that your\sbox{\somebox}{Some text} modification is only visible until the \end{itemize}; after that, the modification is undone. To get around this, prepend any command like \newcommand, \def, \newsavebox, \sbox, etc., with \global, which forces the definition to take place at the global scope and be visible everywhere.
Also, to use quotes in (La)TeX, write ``double quoted'', ``double quoted", or `single quoted'; the " character is only for closing quotes, not opening quotes. Putting this all together gives you the revised snippet
\documentclass{article}
\begin{document}
\newsavebox{\somebox}
\begin{itemize}
\item hello1
\item hello1 \global\sbox{\somebox}{Some text}
\end{itemize}
This should show something, and in fact does: ``\usebox{\somebox}''
\end{document}
I think I can work around this by using \def. like so:
\documentclass{article}
\begin{document}
\begin{itemize}
\item hello1
\item hello1
\global \def \somebox {Some text}
\end{itemize}
This should show something: \somebox
\end{document}

How to get the value of the document title in latex?

I am wondering how I can get the document title in LaTex, for use elsewhere in the document. I just want to be able to echo it.
Using \#title does not work because \maketitle clears \#title. This seems silly to me but that's the way it is. One solution is to redefine \title to save the title somewhere else. For instance,
\def\title#1{\gdef\#title{#1}\gdef\THETITLE{#1}}
then use \THETITLE.
You can do the other way around: \def\MYTITLE{...} then \title{\MYTITLE} and later use \MYTITLE again.
I had success just writing a new command.
\newcommand{\mytitle}{...}
\title{\mytitle}
There is a package called authoraftertitle that does exactly this
\documentclass{article}
\usepackage{authoraftertitle}
\setlength\parindent{0 pt}
\begin{document}
\title{a good title}
\author{a better author}
\date{the best date}
\maketitle
the title is: \textbf{\MyTitle} \\
the author is: \textbf{\MyAuthor} \\
the data is: \textbf{\MyDate} \\
\end{document}
This is a workaround...
\let\titleoriginal\title % save original \title macro
\renewcommand{\title}[1]{ % substitute for a new \title
\titleoriginal{#1}% % define the real title
\newcommand{\thetitle}{#1} % define \thetitle
}
\title{This is my title}
\begin{document}
\thetitle
\end{document}
The short version of the title was ignored here...

New environment in latex using other environments, compiler doesn't find the \end

I'm setting up a new environment for my latex document for consistent tables. It looks like this:
\newenvironment{defaultTable}[2] {
\begin{table}[h]
\noindent
\tabularx{\textwidth}{#1}
\specialrule{0.5pt}{10pt}{0pt} \rowcolor[gray]{.9}
} {
\bottomrule
\endtabularx
\caption{#2}
\end{table}
}
It doesn't seem to find the \end{table} though:
! LaTeX Error: \begin{table} on input line 23 ended by \end{document}.
Is there a way to avoid this?
Replace \begin{table} with \#float{table} and replace \end{table} with \end#float.
The \#float and \end#float are LaTeX's internal commands for starting and ending the float environment.
You'll also want to follow Alexey's advice on the #2 parameter. Store it in the first part of your environment (\gdef\mycaption{#2}) and then recall it later \caption{\mycaption} in the second part. Put \def\mycaption{\relax} just before the \begin{defaultTable} line.
Also, since \#float and \end#float have # signs in them, if this code is in the preamble of your document file (instead of say, a .sty file), you'll need to put \makeatletter before your \begin{defaultTable} and also \makeatother after \end{defaultTable}.
You can use #2 in the end if you use the xparse mechanism:
\usepackage{xparse}
\NewDocumentEnvironment{defaultTable}{+m+m}{%
\begin{table}[h]
\noindent
\tabularx{\textwidth}{#1}
\specialrule{0.5pt}{10pt}{0pt} \rowcolor[gray]{.9}
} {%
\bottomrule
\endtabularx
\caption{#2}
\end{table}
}
You can not use #2 in the last argument of the \newenvironment macros. You should use #1..#9 in the second argument only.
Save your #2 to \tempa (or any macros). And use \tempa in the caption.
\newenvironment{defaultTable}[2]{
\begin{table}[h]
\def\tempa{#2}
\noindent
\tabularx{\textwidth}{#1} \specialrule{0.5pt}{10pt}{0pt} \rowcolor[gray]{.9}
}{
\bottomrule
\endtabularx
\caption{\tempa}
\end{table}
}
I've has the same problem, and it is because of the "\end{tabularx}". The solution is:
\newenvironment{defaultTable}[3] {
\begin{table}[h]
\caption{#2}
\noindent
\begin{tabularx}{\textwidth}{#1}
\specialrule{0.5pt}{10pt}{0pt} \rowcolor[gray]{.9}
#3
\bottomrule
\end{tabularx} } {
\end{table} }
So you define the rows as a parameter.
Regards,
Eric
You could also just use a \newcommand similar to Eric's solution.
\documentclass{article}
\usepackage{tabularx}
% The table design.
\newcommand{\defaultTable}[2]{
\begin{table}[h]
\begin{tabularx}{\textwidth}{cc}
Column A & Column B \\
#2
\end{tabularx}
\caption{#1}
\end{table}
}
\newcommand{\defaultTableRow}[2]{#1 & #2 \\}
\begin{document}
% The creation of a table.
\defaultTable{Example}{
\defaultTableRow{bla}{0815}
\defaultTableRow{blup}{0815}
}
\end{document}
This will avoid both your problems (the missing \end{table} and the error when referencing arguments in the environments closing code) without much hassle.
In fact I also like the idea of separating the table design from the table data. Especially if you create multiple tables that need to look equal.

Resources