[Tex/LaTex] Generate a square and line

boxesframedrules

how should i write a command to automatically place a box on the left side wherein this box can contain text and beside the box are lines which depends on an argument.

Best Answer

Without more details about the width and height of the framed box and a MWE, this is a raw answer:

\documentclass{article}
\usepackage{pgffor}
%\usepackage{setspace}
\newcommand\leftbox[1]{%
\par\noindent
\begin{minipage}[t]{.45\textwidth}
\fbox{%
\parbox[t][5cm]{\dimexpr\textwidth-2\fboxrule-2\fboxsep}{%
#1}%
}%
\end{minipage}%
}%
\newcommand\lines[1]{%
\hfill
\begin{minipage}[t]{.45\textwidth}%
\noindent
\foreach \x in {1,...,#1}{%
\rule{\textwidth}{1pt}\\[1em]}%
\end{minipage}%
}%
\begin{document}
\leftbox{text will be placed here inside this box with a frame}\lines{4}
\end{document}

enter image description here

The pgffor package can be avoided by using (Thanks to Gonzalo):

\newcounter{lines} 
\newcommand\lines[1]{% 
\hfill 
\begin{minipage}[t]{.45\textwidth}% 
\loop \ifnum\value{lines}<#1\relax 
\rule{\textwidth}{1pt}\\[1em] 
\stepcounter{lines}% 
\repeat 
\end{minipage}
}