0

What I have in LyX is this:

enter image description here

I've added to the preamble this line:

\global\setlength{\parskip}{20pt}

I am thus expecting a 20pt space between every line. However, this doesn't happen within the Parbox. My output:

enter image description here

Question: What should I do to achieve the 20pt space between lines 3. and 4. above? I would like this to be accomplished globally (i.e. across all Parboxes in my document).

LaTeX code (exported from LyX):

%% LyX 2.2.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{calc}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\global\setlength{\parskip}{20pt}

\makeatother

\usepackage{babel}
\begin{document}
1. Hi

2. Hi

\noindent{\fboxrule 3pt\fboxsep 6pt\fbox{\parbox[t]{1\columnwidth - 2\fboxsep - 2\fboxrule}{%
3. Hi

4. Hi%
}}}
\end{document}
1
  • aside from the use in \parbox note that the syntax \global\setlength is not guaranteed to make a global definition (and does not for example if the core calc package is loaded, as you have here) – David Carlisle Feb 23 '18 at 7:45
1

You can add in your user specified commands these:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setlength{\parskip}{20pt}
\let\oldparbox\parbox
\renewcommand\parbox[3][t]{\oldparbox[#1]{#2}{\setlength{\parskip}{20pt}#3}}
\makeatother

Edit: Thenext "PS" is wrong: (See David's comments) PS: I didn't really knew if the default optional parameter in parbox was t, but I looked for it and now I know it is. These sentence between "bolds" is not true

My Excuse: I just "googled" and had these results as first:

enter image description here

I saw the link with title \parbox and just read from the last two lines the above wrong sentence...

So, I learned the lesson... Always double check your sources and don't just trust what you see in google by a "distance"

10
  • Question: Am I supposed to replace the #1, #2, #3 with some numbers? – user45727 Feb 23 '18 at 6:38
  • @KennyLJ Not at all! It is just a redefinition of \parbox command that takes 3 arguments (an optional and two mandatory). These numbers are references on the arguments of the command parbox that redefined to include the parskip redefinition inside parbox (private) environment – koleygr Feb 23 '18 at 6:44
  • 1
    the default position for \parbox is c and this and chanes it to t removes all the other optional parameters for height and vertical position, also in general for a command with optional arguments the \let\old... form doesn't work although the optional arguments to parbox are done "by hand" not via \newcommand so you might get lucky. – David Carlisle Feb 23 '18 at 7:44
  • @DavidCarlisle I found what I said here : herbert.the-little-red-haired-girl.org/html/latex2e/…. Also, started with \def but changed it to \newcommand after testing and show it works. Thanks for your comment. – koleygr Feb 23 '18 at 7:53
  • 1
    @koleygr Well, if you write that t is the default, it’s wrong. – egreg Feb 23 '18 at 16:59
1

I understand that this is no direct answer to your question and certainly some overkill. However, if you want to draw boxes without shifting the text (in your example, 3 and 4 are shifted a bit to the left), you can always use TikZ overlays.

\documentclass[english]{article}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{fit}
\newcommand{\tikznode}[2]{\tikz[remember picture,baseline=(#1.base)]{\node(#1)[inner sep=0pt]{#2};}}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\global\setlength{\parskip}{20pt}

\makeatother

\begin{document}
1. Hi

2. Hi

3. Hi\tikznode{3}{\strut}

4. Hi\tikznode{4}{\strut}%
\begin{tikzpicture}[overlay,remember picture]
\node [fit=(current page text area.west|-4.south) (current page text
area.east|-3.north),draw,ultra thick,rectangle]{};
\end{tikzpicture}
\end{document}

enter image description here

This is certainly an overkill if you just want to draw these boxes, however if you want to do fancier things this may be a reasonable option.

1

Since you seem to want the \parskip in every \parbox:

\documentclass{article}

\newlength{\normalparskip}
\setlength{\normalparskip}{20pt}
\AtBeginDocument{\setlength{\parskip}{\normalparskip}\setlength{\parindent}{0pt}}

\makeatletter
\g@addto@macro{\@parboxrestore}{\setlength{\parskip}{\normalparskip}}
\makeatother

\newcommand{\framedparbox}[2][c]{%
  \noindent
  \begingroup
  \setlength{\fboxrule}{3pt}%
  \setlength{\fboxsep}{6pt}%
  \fbox{\parbox[#1]{\dimexpr1\columnwidth - 2\fboxsep - 2\fboxrule}{#2}}%
  \endgroup
}

\begin{document}

1. Hi

2. Hi

\framedparbox[t]{%
3. Hi

4. Hi%
}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy