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 using the following code to have LaTeX fill paper forms for bank payments. The single cells in the form have a maximum width so my question is the following: Can I make LaTeX highlight those text sequences that exceed a predefined width e.g. in red?

If for example the "Account holder" text get too long I'd like to have it appear in red font color in the PDF.

\documentclass[12pt]{scrartcl}
\usepackage[a6paper,landscape,left=0cm,top=0cm,right=0cm,bottom=0cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ocr}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}

\begin{document}\ocrfamily 

\begin{textblock}{3.5}[0,0](0.8,3.5)1234567890\end{textblock}

\begin{textblock}{6}[0,0](4.8,3.4)Account holder\end{textblock}

\begin{textblock}{2.5}[0,0](11.75,3.5)40,00\end{textblock}

\begin{textblock}{12}[0,0](0.75,5)Some Description\end{textblock}

\end{document}

bargeld

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Taking Fran's code just a teeny bit further, one can test the length of the item and compare it to the allocated size, and only do the \fbox if it is exceeded.

\documentclass[12pt]{scrartcl}
\usepackage[a6paper,landscape,left=0cm,top=0cm,right=0cm,bottom=0cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ocr}
\usepackage{xcolor}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}

\newcommand\BankForm[4]{%
\begin{textblock}{#1}[0,0](#2,#3)%
\makebox[0pt][l]{#4}% 
\setbox0=\hbox{#4}%
\ifdim\wd0>\hsize
  {\color{red}\fbox{\makebox[\hsize][l]{\phantom{#4}}}}% Uncomment to show edges 
\fi
\end{textblock}
}

\begin{document}\ocrfamily 

\BankForm{3.5}{0.8}{3.5}{1234567890}
\BankForm{4}{4.8}{3.5}{Too long account}
\BankForm{2.5}{11.75}{3.5}{40}
\BankForm{12}{0.75}{5}{Some Description}

\end{document}

enter image description here


If the emphasis level needed to be increased, the text itself could also be made in the highlight color:

\documentclass[12pt]{scrartcl}
\usepackage[a6paper,landscape,left=0cm,top=0cm,right=0cm,bottom=0cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ocr}
\usepackage{xcolor}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}

\newcommand\BankForm[4]{%
\begin{textblock}{#1}[0,0](#2,#3)%
\makebox[0pt][l]{#4}% 
\setbox0=\hbox{#4}%
\ifdim\wd0>\hsize
  \textcolor{red}{\makebox[0pt][l]{#4}%
  \fbox{\makebox[\hsize][l]{\phantom{#4}}}}% Uncomment to show edges 
\else
  \makebox[0pt][l]{#4}% 
\fi
\end{textblock}
}

\begin{document}\ocrfamily 

\BankForm{3.5}{0.8}{3.5}{1234567890}
\BankForm{4}{4.8}{3.5}{Too long account}
\BankForm{2.5}{11.75}{3.5}{40}
\BankForm{12}{0.75}{5}{Some Description}

\end{document}

enter image description here

share|improve this answer

MWE

An approach to check that is show a box with the horizontal size of the text blocks. In this MWE, your only need to uncomment the line 16 to show the red boxes.

\documentclass[12pt]{scrartcl}
\usepackage[a6paper,landscape,left=0cm,top=0cm,right=0cm,bottom=0cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ocr}
\usepackage{xcolor}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}

\newcommand\BankForm[4]{%
\begin{textblock}{#1}[0,0](#2,#3)%
\makebox[0pt][l]{#4}% 
%{\color{red}\fbox{\makebox[\hsize][l]{\phantom{#4}}}}% Uncomment to show edges 
\end{textblock}
}

\begin{document}\ocrfamily 

\BankForm{3.5}{0.8}{3.5}{1234567890}
\BankForm{4}{4.8}{3.5}{Too long account}
\BankForm{2.5}{11.75}{3.5}{40}
\BankForm{12}{0.75}{5}{Some Description}

\end{document}
share|improve this answer

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.