How do I change the amount of whitespace between sections in Latex? - layout

How do I modify the distance between the end of a section and the header of the next section in a Latex document?

You can configure the style of section headings, including spacing, using the titlesec package. There's a 'compact' option for simple reduction of space, or you can specify specific values using the more advanced options (see the documentation on the linked page for the gory details).

An alternative to titlesec is to redefine the section command, as in the following snippet. Note that beforeskip and afterskip are the variables you're interested in. The code itself is just the first few lines. It's followed by a lengthy comment to remind me of the definitions when I cut and paste the whole thing from one document to another. The code, by the way, is more or less from the indispensable book, The LaTeX Companion, Second Edition.
\makeatletter
\renewcommand\section{\#startsection {section}{1}{\z#}%
{-2.5ex \#plus -1ex \#minus -.2ex}%
{1.3ex \#plus.2ex}%
{\centering\bfseries}}
% \#startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}
% optional * [ALTHEADING]{HEADING}
% Generic command to start a section.
% NAME : e.g., 'subsection'
% LEVEL : a number, denoting depth of section -- e.g., chapter=1,
% section = 2, etc. A section number will be printed if
% and only if LEVEL gt or eq the value of the secnumdepth
% counter.
% INDENT : Indentation of heading from left margin
% BEFORESKIP : Absolute value = skip to leave above the heading.
% If negative, then paragraph indent of text following
% heading is suppressed.
% AFTERSKIP : if positive, then skip to leave below heading,
% else - skip to leave to right of run-in heading.
% STYLE : commands to set style
% If '*' missing, then increments the counter. If it is present, then
% there should be no [ALTHEADING] argument. A sectioning command
% is normally defined to \#startsection + its first six arguments.
\makeatother

Related

Sublime Text 3: How to do multi-line selection that excludes blank lines?

I have some scripts in Stata written as follows:
* 1. count of firms in each bin
grouplabs Inear_dist_km_0_10 Inear_dist_km_10_30 Inear_dist_km_30_60 Inear_dist_km_60_100 Inear_dist_km_100_150 Inear_dist_km_morethan150, groupvar(Inear_dist_km_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_gr !=1, over(Inear_dist_km_gr) name(n1)
* 2. count of firms in each bin (bigger bins)
grouplabs Inear_dist_km_0_20_v2 Inear_dist_km_20_40_v2 Inear_dist_km_40_60_v2 Inear_dist_km_morethan60_v2, groupvar(Inear_dist_km_v2_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_v2_gr !=1, over(Inear_dist_km_v2_gr) name(n2)
* 3. GGK firm level bins
grouplabs Inear_dist_km_GGK_0_10 Inear_dist_km_GGK_10_50 Inear_dist_km_GGK_morethan50, groupvar(Inear_dist_km_GGK_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_GGK_gr !=1, over(Inear_dist_km_GGK_gr) name(n3)
I need to add the character ; at the end of each line, but not in the blank lines between each script. I have tried the Split into Lines trick to get multiple cursors at the end of each line, but the selection also includes the empty lines in between. This results in
* 1. count of firms in each bin;
grouplabs Inear_dist_km_0_10 Inear_dist_km_10_30 Inear_dist_km_30_60 Inear_dist_km_60_100 Inear_dist_km_100_150 Inear_dist_km_morethan150, groupvar(Inear_dist_km_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_gr !=1, over(Inear_dist_km_gr) name(n1);
;
* 2. count of firms in each bin (bigger bins);
grouplabs Inear_dist_km_0_20_v2 Inear_dist_km_20_40_v2 Inear_dist_km_40_60_v2 Inear_dist_km_morethan60_v2, groupvar(Inear_dist_km_v2_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_v2_gr !=1, over(Inear_dist_km_v2_gr) name(n2);
;
* 3. GGK firm level bins;
grouplabs Inear_dist_km_GGK_0_10 Inear_dist_km_GGK_10_50 Inear_dist_km_GGK_morethan50, groupvar(Inear_dist_km_GGK_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_GGK_gr !=1, over(Inear_dist_km_GGK_gr) name(n3);
How can I exclude the empty lines from the selection so that only lines with characters in it will have ; at the end? I appreciate your help.
If you're sure that your blank lines are really blank and not filled with whitespace characters use regex substitution by pressing ctrl+H, search for (?<!^)$ and replace with ;.
The regex says: find an end of line ($) not directly after ((?<!…)) the beginning (^).
Else search for (?<=\S)$ but make sure you don't havy any trailing spaces or tabs.
How to 'make sure': find them with [^\S\n]+$ and delete.
The first regex says: find an end of line directly after ((?<=…)) a non-whitespace character, including linebreak.
The second regex says: find a sequence (…+) of characters that are not any of ([^…]) non-whitespace characters or linebreak -- i.e. a sequence of whitespace characters excluding the linebreak -- and then the end of line.
The most visual and friendly way might be to
find your blank lines with ctrl+F, search for ^\s*$,
select all with alt+enter,
menu > Selection > Invert Selection (now you've highlighted inly the non-blank lines),
go on with the original Split into Lines trick.

In PyQt QTreeView item, how to set color for specific column blocks

With PyQt4 based QTreeView, I've created 2 xml tree widgets. From both the trees, want to compare selected items and highlight the difference. For e.g.,
Left String : "CompareString"
Right String : "ComPareStringRight"
The observations of the diff :
Left[0:2] is same as Right[0:2]
Left[3:3] differs with Right[3:3]
Left[4-12] is same as Right[4-12]
Right[13-17] is not present in Left
Now, want to set colors according to :
matching characters - default
Differing characters - Orange
Added characters - Green
Deleted characters - Red
How can I implement this? Unable to find any reference implementation to pick up from. Pls suggest a way forward.
class QCustomDelegate (QItemDelegate):
global showDiffPaint
def paint (self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex):
column = indexQModelIndex.column()
if showDiffPaint == 1:
QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
else:
QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
After digging, found it useful to convert text into html, and present as below.
However, found bugs due to " and < and > characters display. which I think I need to escape somehow...
options = QStyleOptionViewItemV4(option)
doc = QTextDocument()
doc.setHtml(txt1)
doc.setTextWidth(option.rect.width())
style = QApplication.style()
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
textRect = style.subElementRect(QStyle.SE_ItemViewItemText,
options)
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)

Get length of current line

I'm trying to add an indicator in my statusline for the total length of the line (not just the cursor column position, which can be shown with %c). How do I do this?
To get the contents of a line as a string, use getline(<line number>).
To get the contents of the current line as a string, you can use getline(".").
To get the length of a string, you can use strlen(<string>).
Putting it all together, we get strlen(getline(".")). To add it to your statusline, simply:
statusline += "%{strwidth(getline('.'))}"
or for vim-airline (what I use)
" can be any section; this is for section z (right hand side)
let g:airline_section_z = "%{strlen(getline('.'))}"

Highlight predetermined locations in textbox

I have been using python 3.4 and tkinter to create an application to parse logs and format data and display results in a text widget. I would like to highlight text that is located at a known position on each line in the text window. I have seen similar highlighting questions regarding highlighting text in text widgets on this site and it has been very helpful.
My problem is that I don't need to search for the string or characters to highlight. I have the locations that I want to highlight and it could be any character in that location including white space. For example: I would like to highlight positions 0, 20, 40 on each line (eg: index 1.0, 1.20, 1.40, 2.0, 2.20, etc).
Since it is large files being written to the textbox I have to do this for the entire scrollable text window, so I need to maintain the textbox line number position.
When referring to a location in a text widget, you can append modifiers to indicate relative positioning. For example, given the position "1.0", the next position can be identified as "1.0+1c" (or "1.0+1char"). So, to highlight a single character at a given offset, make the start of the range the offset, and the end of the range one character greater.
Here's a quick hack that takes one or more "positions" and highlights that position on each line:
def highlight(text, tag, *positions):
last_line = int(text.index("end-1c").split(".")[0])
for linenumber in range(1, last_line+1):
line = text.get("%s.0" % linenumber, "%s.0 lineend-1c" % linenumber)
line_length = len(line)
for pos in positions:
if pos <= line_length:
start = "%s.%s" % (linenumber, pos)
end = start + "+1c"
text.tag_add(tag, start, end)
usage:
text = Text(...)
text.tag_configure("highlight", ...)
...
highlight(text, "highlight", 0, 20, 40)

How to improve this vim mapping to format/align similar lines

Recently I was in need of a faster way to format similar code lines according a common character (usually =). For example, I want to format this:
myVar = getMyVar();
myLongerVar = getMyLongerVar();
myYetLongerVar = getMyYetLongerVar();
into that:
myVar = getMyVar();
myLongerVar = getMyLongerVar();
myYetLongerVar = getMyYetLongerVar();
then I wrote the following mappings:
" query used to find the common character. In this case i'm setting it to "find the ="
let g:defformatquery = "f="
" set current line as having the longer size till the common character
nnoremap <Leader>gm 0
\:execute "normal " . g:defformatquery<CR>
\:let b:epos = getpos(".")[2]<CR>
" format current line according to the position acquired above
nnoremap <Leader>g= 0
\:execute "normal " . g:defformatquery<CR>hvgeld
\:execute "normal " . (b:epos - getpos(".")[2]) . "i "<CR>
To use them I have to perform these steps (assuming , is my <Leader>):
position the cursor in the line with the longer text before the = sign (the third line in the example provided, myYetLongerVar)
press: ,gm
for each line I want to format, position the cursor there and press ,g=
Although this works, the process is kinda slow.
I want to create a function that would format the entire selected area at once. Then I could just create one map for the function.
Any ideas?
You should try the Align plugin.
For example, to align some selected lines (selected with v or CTRL-v) according to the = sign, you just type:
:Align =
Or to align from line 34 to 39:
:34,39Align =

Resources