Graphviz: aligning a graph wrt its label - alignment

By default, Graphviz centers the graph relatively to its caption (label):
graph {
label="lorem ipsum dolor sit amet consectetur adipiscing elit"
A -- B
}
How can I align the graph to the left, i.e., make A, B and the initial of "lorem" vertically aligned?
The attributes labeljust and labelloc have other purposes, and I cannot see anything in the reference to achieve this result.

(it helps it include your source as text, not png)
No direct way, but (if needed) use invisible nodes and/or node width to get the graph wide enough to meet your needs. Then use the labeljust attribute to to justify the label to the left (or right) of the entire graph.
graph {
// does not seem to work size="8!"
label="abcdefghijklmnopqrstuvblahblah" labeljust=r
{rank=same a node[style=invis width="2."] x1 x2 edge[style=invis] x1--a--x2}
a--b
}
giving:

Related

How doesn't UILabel implementation intrinsicContentSize?

As we known, UILabel has intrinsicContentSize, my puzzle is when we pin a label to it's superview with leading and trailing offset 10 for example, and set the numberOfLines to 0, assume the superview is a viewcontroller's view that has a width 320, and how label knows it's width is 300.
Another, when there are mutiple constraint that the label is compressed, and how the label know it's compressed and recalculate it's size?
The intrinsicContentSize is independent of any context, including any constraint applied to the label. This is, actually, the meaning of intrinsic.
So when you ask for the intrinsicContentSize of a label, it does not know that its width is gonna be 300, and indeed it returns any width that fits its content. Go on, check it: ask the the intrinsicContentSize of a label which contains "foo", or "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae sapien nec elit tongue incident." You won't get the same result.
Know you may wonder: if the intrinsicContentSize is (52,21) or (633,21), why on earth does it end at (300, 21)?
Well the answer is simple: the intrinsicContentSize generates implicit constraints whose priorities are controlled by the contentHuggingPriority and contentCompressionResistancePriority of the label. Those are generally less than 1000. On the opposite, the priority of the leading and trailing offsets are 1000, the maximum. So the offset constraints win in the final layout, and the label ends with a 300 width.
Now try to set contentHuggingPriority and contentCompressionResistancePriority to 1000: you will see a conflict. Do you see why?

Text selection position in pdf.js

I have the text selection enabled in my PDF.js. When a user selects some text I would like to know what is the starting position of that selection in reference to the underlying file stream. The idea is to return the absolute position of the selection within the file.
Example:
E.g. the selected text might be returned with the absolute position char=300,312
Lore ipsum My Selection Lore ipsum Lore ipsum Lore ipsum Lore
Is this kind of reverse engineering even possible with PDF.js?

Graphviz: Control node align in a subgraph

Consider the following subgraph, with 5 Mrecod nodes:
Is there a way to force a vertical orientation, with the nodes above each other? I've tried rankdir=TB in the subgraph, with no effect.
I am running graphviz under Ubuntu with no special parameters:
dot -Tpng graph.dot -o img/graph.png
Adam, just to clear up a couple of potentially confusing points:
I'm pretty sure that the rankdir attribute applies to the entire graph, you cannot isolate that particular subgraph.
rankdir=TB is the default value to begin with, so adding it isn't really going to do anything.
That said, if I am reading your subgraph correctly, it looks like:
You have a collection of 5 record-type nodes in a cluster.
Each of those nodes have inbound edges from one or more nodes outside the cluster.
None of the nodes within the cluster have edges between them.
If that's correct, then the nodes in your subgraph have the same rank (or probably do, depending upon the rank of the nodes that connect to them). Setting rankdir=LR (or rankdir=RL) will change the orientation of that subgraph so the nodes are aligned vertically, but it will also change the alignment of the overall graph.
One way to get just those nodes to be aligned vertically is to add an invisible edge between them. For example, if you have nodes A, B, C, D and E, your cluster definition might look something like this:
digraph G {
// ...skipping stuff outside the cluster...
subgraph clusterFoo {
node [shape=record]
A [label="..."]
B [label="..."]
C [label="..."]
D [label="..."]
E [label="..."]
edge [style=invis]
A -> B -> C -> D -> E
}
}
Adding the edges will force the nodes in the subgraph to have a different rank, so the default rankdir=TB will lay out the nodes from top to bottom rather than from left to right. The style=invis attribute on these "false" edges will make them invisible.
If you want to tweak the spacing or alignment of the nodes within the cluster you might also want to play with edge attributes such as weight or minlen/attrs.html#d:minlen), or consider constraint=false on the inbound edges.
If I've misinterpreted your graph or if this doesn't help you at all, can you update your question to add a minimal example of the DOT file you are working with?
PS: On Ubuntu, you can use:
dot -Txlib graph.dot
to quickly open up a window with a rendering of the graph in graph.dot without first writing it to a file. The rendered image will even automatically update when you modify the source file.

Graying out texts with/without lines with LaTeX?

This is a screen capture from Pragmatic Bookshelf.
How to make this boxed text with LaTeX? It has it's own heading with underline, and uses color.
And how to make some text with gray background as follows?
http://img20.imageshack.us/img20/7351/screenshot20100718at916.png
Added
Konrad's method works, but it looks like that it doesn't work well with multicolumn package.
Tonio's method shows the gray only for the characters, but I want to have the gray box expanded to the end of \textwidth.
http://img714.imageshack.us/img714/8417/screenshot20100718at247.png
I posted another question with respect to the \texwidth, and it seems to working anyway.
The rounded box is most easily created using TikZ:
\begin{tikzpicture}
\draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\textwidth] {
Lorem ipsum dolor sit amet \dots
};
\end{tikzpicture}
You should use the color package.
For example,
\colorbox{red}{Black text on red background}
creates a black text, with a red background.
A good description of the color capabilities can be seen here, and an extended example here.

LaTeX book class: Twosided document with wrong margins

I am trying to write my thesis in latex... Cannot get the layout straight though :?
I'm using the following document class:
\documentclass[11pt,a4paper,twoside,openright]{book}
My problem is: on the odd numbered pages there is a big margin right, and a small margin left - it should be the other way round... (for binding & stuff)
I am a little puzzled by this -- am I just to stupid to see the obvious? The odd page numbers appear on the 'right' page of a bound document, so there needs to be a larger gutter margin on the left for binding -- and vice versa. Right?
Why does LaTeX not behave like this?
Here is the full code to produce a small Tex file that shows my problem:
\documentclass[11pt,a4paper,twoside,openright]{book}
\begin{document}
\chapter{blah}
Lorem ipsum ius et accumsan tractatos, aliquip deterruisset cu usu. Ea soleat eirmod nostrud eum, est ceteros similique ad, at mea tempor petentium. At decore neglegentur quo, ea ius doming dictas facilis, duo ut porro nostrum suavitate.
\end{document}
Edit:
I know about a lot of ways to manually specify the page margins, like
\setlength{\oddsidemargin}{53pt}
or ...
\usepackage[lmargin=1cm,rmargin=2.5cm,tmargin=2.5cm,bmargin=2.5cm]{geometry}
I just wanted to use the default settings and don't understand why they do not behave as expected.
I had the same problem. Anyhow, here the "simple" solution (put it in your preamble):
\let\tmp\oddsidemargin
\let\oddsidemargin\evensidemargin
\let\evensidemargin\tmp
\reversemarginpar
Cheers,
Chris
Edit: Contrary to the previous solutions, the provided code does not change the style of the document :)
No, that's right. The odd pages should have a bigger margin. If you take a twosided book, you have 3 margings: On the left, in the middle, on the right. Every margin should be the same size. The one in the middle is build by two margins from each side. So it has to be smaller.
If you want to add a bindingoffset, you need to use the package geometry:
\usepackage{geometry}
\geometry{bindingoffset=1cm}
or use another class, like the KOMA-classes:
\documentclass[11pt,a4paper,twoside,openright,BCOR=1cm]{scrbook}
The extra space is for the margin notes. In general, to see what's going on with your layout, you can put \usepackage{layout} in your preamble, and then stick \layout in your document to get a diagram and listing of geometry settings.
In your case, as I say, what's going in is the extra space for margin notes. If you don't want it, use \setlength{\marginparwidth}{0pt}.
If you have the time and inclination to learn more about this, and many other things about page layout and document design in general, I believe that studying the memoir package will give you an excellent return on your investment.
In particular, memdesign.pdf gives the underlying principles a thorough going-over, and memman.pdf is a comprehensive (though large!) reference.
In the case of the memoir class.
The margins are correct. There is more space to the right of the odd pages because of margin notes. As #etaoin pointed out, you can see the page layout with \usepackage{layout} and putting \layout within the document environment.
I don't use margin notes, therefore my solution is to reduce the \marginparwidth to 0 or set it to a small value.
You can do that directly by setting the length
\setlength{\marginparwidth}{0pt}
or using the command \setmarginnotes described in the documentation memman.pdf.
\setmarginnotes{0pt}{0pt}{0pt}
However, that didn't worked out for me immediately because the text width remained the same.
My final solution is to set a desired width to the margin note, then whatever width you gained you should add it to the text width. On the odd pages this works fine because the text expands to the right. However, on the even pages the text grows to the right but your free space is to the left.
You have to correct this by decreasing the even side margin as well.
Here's the complete solution:
% the new margin note width will be a fraction of the old one
\newlength{\notewidth}
\setlength{\notewidth}{0.2\marginparwidth}
% deltanotewidth is the space that we gain
\newlength{\deltanotewidth}
\setlength{\deltanotewidth}{\marginparwidth}
\addtolength{\deltanotewidth}{-\notewidth}
% update the note width
\setlength{\marginparwidth}{\notewidth}
% the text width grows
\addtolength{\textwidth}{\deltanotewidth}
% the even side margin reduces to fit the bigger text
\addtolength{\evensidemargin}{-\deltanotewidth}

Resources