Let’s Learn LaTex: Part 4

I sort of neglected my Let’s Learn LaTex series for a while now. The last LaTex related post I made was in April and now it is already November. I figured I might as well get back to it, and hopefully if you were following along you can refresh yourselves using the link above.

Last time I promised to explain tables, but then I realized that tables are quite a big topic so I will split this lesson into two parts. Today I will talk about basic table structure, and next time I’ll outline some more advanced table tricks.

How do you make a table in LaTex? How do you make a list? If you recall from the last post, lists were LaTex environments. So are tables. Instead of using enumerate or itemize environment, you use tabular instead. The \begin{tabular} and \end{tabular} keywords set it up up just like lists. Let me show you a simple one:

\begin{tabular}{ l c r }
  foo1 & bar1 & baz1 \\
  foo2 & bar2 & baz2 \\
  foo3 & bar3 & baz3 \\
\end{tabular}

It will make this fine looking table:

Basic table

It is spartan and simplistic but we can fix that in a few seconds. Let’s talk about the basics. The tabular environment takes an argument which is a textual string that “describes” the columns, and it accepts following literals:

  • l – Left aligned column
  • c – Centered column
  • r – Right aligned column
  • | – A vertical line / column divider

It does not really matter which character you use in the example above, because all the columns are of equal width and LaTex will do auto-kerning and alignment on them as usual.

Once you define the columns, you just start typing your data in, and place the & character when you want to skip to the next column and you end the row with the \\. Naturally if you want to use the & symbol in your table you will need to escape it as \&

Now let’s add some lines. You can use the | (pipe character) to add vertical lines in the column definition string and \hline command to add vertical lines in the body of the table like this:

\begin{tabular}{| l | c || r |}
\hline
  foo1 & bar1 & baz1 \\
\hline
  foo2 & bar2 & baz2 \\
\hline
  foo3 & bar3 & baz3 \\
\hline
\end{tabular}

The result will look like this:

Table with some lines

Much nicer, eh? You should note that LaTex does not have the equivalent of the <th> html tag that would automatically style a row as a column header. You have to do this sort of thing manually either by using multiple \hline commands or by using \textbf or other formatting on individual table cells.

Similarly to HTML tables, the tabular environment won’t wrap long text lines around. This behavior is by design, but it often catches new LaTex users by surprise when their table slides right off the page. Let’s test it and create a nice table with some long sentences. To make it more fun lets use everyone’s favorite panagram featuring that pesky brown fox:

\begin{tabular}{| l | l |}
\hline
  Incorrect version & The quick brown fox jumped over the lazy dog. \\
\hline
  Correct version & The quick brown fox jumps over the lazy dog. \\
\hline
\end{tabular}

Yes, despite the popular belief the brown fox jumps over the dog all the time – like right now for example. If he had jumped over him once at some point in the past and never did it again he would ruin the panagram by ommiting the letter ‘s’. But I digress. For our purpose let’s say we have a rather narrow page. In such case the table above could easily end up looking like this:

Table too wide for the page

Fortunately this is easily fixable by using p{w}, m{w} or b{w} instead of l, c and r where w is some width attribute:

  • p{w} – top aligned wrapped paragraph column
  • m{w} – middle aligned wrapped paragraph column
  • b{w} – bottom aligned wrapped paragraph column

The value of w must be a number followed by measurement unit such as in (inches), cm (cemtimeters) or em (internal LaTex measure which defaults to the width of letter ‘m’ in the current font). Let’s try this with our example:

\begin{tabular}{| l | p{10em} |}
\hline
  Incorrect version & The quick brown fox jumped over the lazy dog. \\
\hline
  Correct version & The quick brown fox jumps over the lazy dog. \\
\hline
\end{tabular}

Here I set the width of the second column to be approximately ten widths of the letter m, which resulted in this output:

Table with restricted width

As you can see, the result is much better.

One of the lovely things about LaTex is that it was written by programmers for programmers. Programmers are lazy beasts, so anything that requires lots of typing or copying and pasting will usually get lumped into some sort of a function. This is true for tables. For example, if you need to define several identical columns, you can use the * (star/asterisk) notation in your column definition. It usually takes the form of:

*{howmany}{columndef}

The value of howmany is a number and the value of columndef is actual column definition (for example c or a p which can be accompanied by some pipe characters to create column border). Let me give you a quick example:

\begin{tabular}{ l | *{4}{c|} }
  Student Name	& HW 1 & HW 2 & HW 3 & HW 4 \\
\hline
  John Smith	& A & B & A & F \\
  Jane Smith	& C & C & F & F \\
  Bob Johnson	& A & F & A & B \\
\end{tabular}

It will look like this:

Table created using the star notation

The last thing I want to show you today is spanning. Sometimes you want to have rows that span more than one column. In HTML tables you can achieve that by sticking an attribute on a <td> tag. Since LaTex uses a much simpler table structure, and the column definition attribute is already overloaded as it is, things get hairier here – but only a little bit.

Essentially instead of typing the columns or rows that need to span, you use a special command such as:

\multicolumn{howmany}{columndef}{content}

Let me give you a quick example:

\begin{tabular}{| l | *{4}{c|} }
\hline
  \multicolumn{5}{|c|}{Homework Grades} \\
\hline
  Student Name	& HW 1 & HW 2 & HW 3 & HW 4 \\
\hline
  John Smith	& A & B & A & F \\
  Jane Smith	& C & C & F & F \\
  Bob Johnson	& A & F & A & B \\
\hline
\end{tabular}

I’m sure you can see the \multicolumn statement replaces an entire row here, but if it didn’t you could still use & characters to the left and right of it. Here is the output:

Table with multicolumn

If you want spanning rows, you will need to use a package called multirow which is something I did not explain yet. Which is why I think the next lesson will be about importing packages and then I will swing back to tables.

Let’s Learn LaTex
<< Prev Next >>
8 Comments

Dystopias and Utopias

In the Twisted Thicket thread Alex gave me the following challenge:

You have a good grasp on the topics of dystopian and utopian worlds. However, I would like to hear your own theory of how we could become both a dystopian society, or utopian. how it would happen ect. yes, im giving you a challenge.

Let’s see if we can tackle this in today’s post. I believe this is sort of a three part question:

  1. How would we become a dystopian society?
  2. How would we become an utopian society?
  3. Can we have a society that is a bit of a mix of the two? (if that’s even possible)

The first part of the question is rather easy to predict. The world could be plunged into a dystopian nightmare rather quickly, and all you need to think about is a single keyword: energy. Right now, our whole civilization depends on constant supply of energy. Our cities, which are the hubs for our commerce, communication and culture simply cannot function without electricity. We use it for air conditioning, waste disposal, pupping water to high rise buildings, transportation, food preservation, communication and etc. It is the life blood of civilized world. Worst part is that currently most of the infrastructure in the western world is almost entirely dependent on non-replenishable, dwindling supplies of fossil fuels. A sharp decline in the supply of oil could easily plunge us into total chaos and break down civilization as we know it.

It goes like this: first the gasoline becomes exuberantly expensive which wrecks most western economies. High gas prices drive food prices. Cities become too expensive to keep running because their infrastructure is essentially bleeding money, and transporting perishables into city stores and restaurants costs fortune. People migrate in droves to suburbs and the country side, hoard gas and fossil fuels and try to survive of the land, while cities go dark one by one. Some areas fare better than others though. Nuclear power plants, wind farms and solar power keep some smaller cities afloat, providing the last safe havens for mega-corporations, millionaires and failing government which struggles to keep the country together even as the communication lanes break down. Global trade is done, because it is just too expensive to fly or ferry things by boats. Long distance domestic commerce is done, because hauling goods is no longer profitable. Eventually you end up with few walled, fortress-cities that still have energy scattered across the map, separated by vast expanses of chaos. Those who were not lucky enough to live in the cities end up either taking up farming, hunting/gathering or join up with roving gangs and war bands to prey on the farmers and hunters. Those in turn organize local governments, militias and etc…

The experience might be a little bit like what I described here. One day the power goes out, and never comes back and you either starve to death, or learn to cope. Some people will cling to their communities, and search for a strong leader to organize them. Others will do the exact opposite – they will seek safety in seclusion. Jean Hegland’s novel Into the Forest is actually a pretty good description of that. After the power goes off and economy collapses two young girls seclude themselves in their wood cabin, and slowly learn to eschew their ties to civilization and essentially go feral, reverting to a hunter, gatherer nomadic lifestyle.

But that’s the worst case scenario, and one we can easily avoid if we only invest in alternate energy ahead of time. Thorium reactors seem to be the most promising solution to our fossil fuel addiction right now. But let’s look at another way we could turn into a weird dystopia.

A while ago, the I Polish SF magazine I subscribe to used to run a column titled “The New Middle Ages” in which the author published his musings on how western democracies are slowly turning “feudal” and tried to extrapolate how this trend could shape the power structures and societies in the future if it continued as he predicted. The whole concept revolved around the idea of increasing social stratification. Rich are getting richer, poor are getting poorer while the middle class starts to fade out of existence. Wealthy and educated people migrate to suburbs, then to gated communities. They educate their kids in exclusive private, corporate sponsored schools, work in gated corporate compounds, etc… Middle class members can either enter corporate serfdom, or be lumped together with the poverty stricken masses at the bottom.

If you have never actually read Oryx and Crake I highly recommend this book. It extrapolates exactly this scenario in which the social elites live and work in heavily defended, comfortable corporate compounds, while the rest of the population tries to eke out the living in almost completely ungoverned urban jungles outside. There things like poverty, perpetual social unrest and gang violence are facts of life. Vestigial government is both corrupt, indebted to the international corporations and almost entirely impotent.

Utopian societies are a little more difficult to predict because they almost never pan out the way they supposed to. Utopia is a model to strive towards, but probably not one that we could achieve. Then again we might never know. My go-to theory when talking about utopian societies is naturally singularity. The thing is, that the whole point of singularity is that we don’t actually know what it will do. It is sort of pointless to speculate how our lives will look after it because we don’t have the frame of reference. But it is fun to do it anyway.

One of the theories is that some of the post-human, self-improving artificial intelligences we create will develop “caretaker” personalities and take upon themselves to create comfortable living conditions for their ancestors/creators. Sort of like we try to save and breed endangered species of animals – only better. I imagine us, old-style humans living in comfortable, weather controlled habitats in post scarcity economies. Energy is virtually an inexhaustible, infinite resource: you simply drop a wormhole into a very low orbit around the star, and siphon all the energy you need on the receiving end. Nano-machinery allows them to disassemble waste on atomic level, and re-use everything. Fusion can be used to make metals and alloys as needed. All is taken care of for you – nothing is bought, nothing is sold. If you need new clothes, your house will “grow” them for you in your closet, and then absorb your dirty clothes once you take them off. If you need food, it is provided for you. The utility cloud of nano-machines that keeps your house clean can also perform medical functions. It will patch up your wounds, prevent your appendix from rupturing and keep you from aging. If you manage to kill yourself somehow, you will be restored from backup that your house automatically takes every time you go to sleep. People devote most of their time entertaining themselves, creating art philosophy, resurrecting old crafts and etc… In this strange world, the act of making a sandwich is elevated to sort-of avant-garde performance art.

Of course it could go the other way too. We could also find our utopias by migrating inward, into virtual worlds. If human mind can be digitized, we may one day have an option to become citizens of a brand new virtual universe: one with infinite worlds, and places to live. Worlds not bound by rules of physics that could never exist in nature. Worlds without hunger, without wars… Well, except for those who enjoy fighting wars. The point is that you make up your own rules as to how you want to live.

I read a short story once (I can no longer recall the title or the author) in which used this model. People lived in simulated worlds. They had no physical needs – but they still gathered and “ate” imaginary food for the taste. They still entertained themselves preparing it, and discussed art and poetry during meals. They had care-free safe sex, and were able to share intimate thoughts and ideas at much deeper level than corporeal humans ever could. They spent time playing games that would be impossible to play with physical bodies, partying and entertaining each other. Every few hundred years people would just leave: burn their imaginary houses and virtual properties, change their name, appearance and move into a new community to shake things up so the populations were in flux, relationships changed and people wouldn’t usually get stuck in a rut forever.

Both these scenarios don’t actually “fix” human nature though, so there would always be violence, jealousy, envy (although in post-scarcity economies people would probably be more envious of ideas or relationships rather than physical things) and suffering. Just in different aspects. In fact, human suffering in these settings would be much more acute. With no death, sickness, hunger or economic strife suffering would in most cases be result of premeditated sadism or malice, and hardly ever accidental. Still, utopian enough I guess.

As to how do we get there? The answer is: technological progress.

Let me quickly wrap this up, by trying to come up with the last one: a utopian dystopia. We need a setting which not only appears to be a utopia, but in fact is one for its inhabitants, but deep down inside it is very, very dysfunctional. I think my favorite example of this comes from Dan Simmon’s Illium novels. In them, technologically advanced post-humans migrated to man made satellite rings that they installed in the sky. They have left the Earth to about a million of old-style humans (our genetically improved descendants). They would live in small communities taken care of mechanical servitors who would provide for all their needs. Servitors would grow their food, prepare it, serve it, manufacture their clothing, build and maintain their shelters and provide for their safety. Every 20 years a person would be taken up into the rings, where they would be stuffed into a “bacta tank” like device that would rejuvenate them. They could also be taken there ahead of schedule in case of an injury or disease. People would move between communities using “fax nodes” – sort of instant teleportation devices around which communities would cluster. After 100 years on Earth, each person was to ascend to the rings and join post-humans in their orbital cities.

While all of this sounds great, there was also a darker side to this utopian society. For one, all old-style humans were illiterate. They lost art, poetry, literature and almost all crafts. They were completely dependent on the servitors and their post-human masters who at some point went away never to come back. No one knows what happened to them, though most assume they still live in the rings but have better things to do than to check up on the boring old-styles. Curiously enough, none of the people who ascends to the rings on their hundredth birthday ever comes back to say hi. Most folks prefer to assume this is because being post-human is just that awesome and try not to think about the alternatives. Not only that, but the Earth itself was partly ruined by the excesses of previous generations. Environment almost wrecked by out of control genetic engineering was now overrun by resurrected prehistoric beasts and man-made mutants. Stockpiles of ancient civilization destroying weapons rotting away and corroding in forgotten places ready to unleash their deadly payloads at some unspecified time in the future. And there is no one in the world who could locate, or disarm them. How is that for an utopia/dystopia mix?

What are your favorite utopian and dystopian settings from movies and literature? How about mixed ones? Can you think about any others?

10 Comments

Themed RPG Characters

Do you ever intentionally cripple your RPG characters for better game play experience? Let me give you an example – in the Fallout New Vegas post Zel mentioned that he played a diplomat character. That means that during character creation he min maxed his stats to create a fragile intellectual with little combat prowess, and during level-ups he heavily favored non-combat skills. I also remember someone blogging about playing Fallout 2 with an exact opposite of that character: a really, really dumb but strong character.

Regretfully, I realized that I have never actually done that. I am all about role-playing, and I do in fact sometimes play dress-up with my characters but I don’t actually remember ever customizing my character build to fit a certain theme. Or rather these themes were always standard: sneaky stealthy character, pure warrior, magic user, etc… When it comes to stats I usually lapse into the min-maxer mentality. I guess that’s my deeply suppressed inner munchkin coming out.

I guess part of the problem is that I rarely re-play role playing games. After all, you don’t usually want to hit insurmountable wall on the first playthrough. So I tend to stick with safe builds most of the time, leaving experimentation to future playthroughs. Those usually never happen, because by the time I’m finished with a given game, I have another shiny one I want to play with. There are some exceptions of course – like Morrowind, but that’s probably because it is impossible to complete all the quest chains for all the factions with a single character. It just can’t be done, because some quest chains will effectively lock you out of the others, and faction reputation does count.

Which brings up another point: most modern games are not long and complex enough to be worth playing multiple times. In games like Oblivion and Fallout for example I was able to complete every single named quest in the entire game (I checked with the wikis) with a single character. There was just no reason to re-play the game after I was done because I have already seen everything. Similarly, even though I loved Mass Effect 2, I have quit my second run halfway through because playing full renegade after full paragon changed almost nothing, other than few conversations. Then again ME2 was not really a game which would allow you to make a really wonky build that would be fun to play with.

So sadly, I don’t have good “themed character” stories to talk about. How about you? Have you ever intentionally crippled your character to conform to some concept? Have you ever played a non-combatant? An intellectual? A diplomat? A dumb brute? Did the game support that character choice? Did it matter? Did it make the game unplayable after certain point? Let me know in the comments.

5 Comments