Four ways to align two elements next to each other in LaTeX

Of course there are more than just four ways to do layout like aligning elements next to each other. In this post, I just want to summarize the four ways I tend to use:

  • Flowfram
  • Table
  • Column
  • Minipage

Note that all code is stripped in order to reduce the length of this post.


Flowfram is a package which has to be included and configured. In the following, I will only list the way how to align two simple image elements next to each other, even though this package provides much more possibilities. Please refer to the documentation for more informations.

% ...






% ...


Good old Table is a method of aligining items too! Note that it is not the inteded purpose of a table cell to contain much more than just text, so you might find additional difficulties inserting an image or a list inside a table. Important for use as a layout tool is simply not to add the borders of the table cells and rows. That simply means no “|” between the float specifiers as well as no \hline or similar in the table.

In the following example, I usepackage{tabularx} in order to get both items the same horizontal space.

           Test left
        } &  {
           Test right


Columns are the way to go for longer parts of the document, or if you even want the whole document splitted into two elements next to each other. You may use the multicol package for a simple solution:

    This text will be split into two columns. 


Minipage is not a package and should be provided automatically by your LaTeX distribution. A minipage is what its name says: a new float environment, a new page, but mini. You can wrap nearly anything inside a minipage and size it the way you want. To align two minipages next to each other, you could do so:

	% minipage with text
	Left hand side
	% Fill the space in between
	% minipage with image
	% textwidth is defined by the minipage, inside here
	caption{An image}
caption{Caption of both sides. Optional.}

What to use when?

Answer the following questions to get to a result. Note that this selection is only based on my current opinion and knowledge and therefore up for changes and challenges.

Do you need a rather configurable column setup and are you ready to read long documentations and learn about internals of a LaTeX package in order to get the most possibilities? Use Flowfram.

Do you need the elements not necessarily to be next to each other but to overflow from one to the other? Use columns.

Are the elements to be placed next to each other the same height, together do not need a specific placement and are not so much new float environments? Use a table (or longtable if longer than one page).

If you answered all these questions above with no, try minipage.

Estimating Electricity Cleanliness for Valuability of Electric Cars

The purpose of this post is to calculate the viable “dirtiness” of electricity for electric cars in order for them to be the better alternative to conventional diesel or petrol powered cars. It is a justification of my own information bubble as well as an answer to the rightly controversial and refuted article by Buchal, Karl and Sinn ​[1]​.

Let us note down the assumptions that will be made, respectively what we will neglect:

  • Neglect the construction, transport and sell of the car
  • Start at the point of “customer buys car” with the estimations
  • Neglect CO2 of fracking, refinery, storage and the transport of the fossil fuels
  • Assume electricity is composed of coal and water
  • Assume water energy has zero CO2 emissions
  • Neglect electricity grid construction

As for the data, we will calculate with the car models chosen in said paper: a Tesla Model 3 and a Mercedes C 220 d. The reference value for the Mercedes is a minimum of 0.134 kg CO2 per Kilometer ​[2]​. This is the value we will want to maximize the coal proportion to.

As for the Tesla Model 3, we calculate with a reported efficiency of 0.148 kWh per Kilometer ​[3]​. With a Li-ion battery efficiency of 99 % ​[4]​, we can safely neglect charge & discharge losses. Taking the global average of power loss by the power grid of 12 % ​[5]​, we require 0.168 kWh of produced power per Kilometer.

As for the CO2 production by coal power generation, we assume the worst case, the highest emissions, being by anthracite coal, of 0.354 kg CO2 per kWh (units converted) ​[6]​. With a proportion of 100 % coal power, our Tesla would be responsible for 0.059 kg CO2 per Kilometer. This is less than half of the emissions of the Mercedes, for the far-from-true assumption of 100 % of electricity coming from coal.

To summarize, a short calculation over the thumb supports the general impression that electric cars do indeed produce less emissions. It has to be noted though that quite a few assumptions were made, although most of them seem to cancel out in the direct comparsion. Also, only the carbon dioxide emissions were regarded, even though this is by no means the only nor a sufficient indicator of the environmental friendliness of an object. The only thing I might consider in a futher revision of these calculations is the production of the battery of the Tesla, as this is the major difference in the manufacture of the two cars.

Finally, if you find any mistakes in my calculations or have any doubts about my assumptions, do not hesitate to write me an e-mail or leave a comment.


  1. [1]
    C. Buchal, H.-D. Karl, and H.-W. Sinn, “Kohlemotoren, Windmotoren und Dieselmotoren: Was zeigt die CO2-Bilanz?” p. 15.
  2. [2]
    “C-Klasse: T-Modell, Preisliste gültig ab 1. Februar 2019.” Mercedes-Benz Schweiz AG.
  3. [3]
    “Tesla Model 3 Standard Range,” Electric Vehicle Database. [Online]. Available: [Accessed: 19-Jun-2019]
  4. [4]
    “Battery University,” BU-104a: Comparing the Battery with Other Power Sources, 28-Mar-2019. [Online]. Available: [Accessed: 19-Jun-2019]
  5. [5]
    “ 6. Efficiency and Power Grids,” Global CCS Institute. [Online]. Available: [Accessed: 16-Jun-2019]
  6. [6]
    “How much carbon dioxide is produced when different fuels are burned?,” U.S. Energy Information Administration, 04-Jun-2019. [Online]. Available: [Accessed: 19-Jun-2019]

My fix to`0 – Using $this not in object context` in Joomla!

After migrating, the Joomla! page would not show up. Instead, only the error “0 – Using $this not in object context” was showing up. In my case, I was able to fix the issue by replacing – in the code of the template – all JFactory::getMenu() with $application->getMenu(), where $application came from $application = JFactory::getApplication().

Note that this may not be the only possible fix for this error. It highly depends on the code you have. Generally, the errormessage indicates the underlying problem: somewhere in Joomla!s code, there is a $this inside a class which – in your code – is used, without the class being instantiated properly. In the case mentioned above, the class is initialized statically. This, because that was valid apparently in elder Joomla! versions.

To find the source of your problem, I recommend to enable Joomla! debugging as well as PHP logging in order to get the full stack trace and find the origin of the wrongly instantiated class.

How to Create a Third-Party Symfony Bundle

Have an awesome library you want to integrate in your Symfony application? Share your code between different Symfony instances? Share your code with other people? Create your bundle standalone and distribute it via Composer! Here is a short overview on how to do it.

To get started, you want to have a Composer & a git instance (if you follow the general practice to publish your bundle on a git-based central repository, such as GitHub or GitLab) running. All a Symfony third-party bundle has to be is a composer package. Everything else is bonus. To make your project a composer package, you add the `composer.json` file if you did not already. In it, you specify the name, properties and dependencies of your bundle. Comparsion with other bundles helps to get an impression of what to put in there.
Basically, it could look like mine for my PlaceholderBundle:

    "name" : "bernhard-webstudio/placeholder-bundle",
    "type" : "symfony-bundle",
    "description" : "Symfony bundle to generate placeholders for images",
    "keywords" : ["Symfony", "Placeholder"],
    "homepage" : "",
    "license" : "MIT",
    "authors" :
            "name" : "Tim Bernhard",
            "email" : "",
            "homepage" : "",
            "role" : "Developer"

After adding the boni, you will want to publish your bundle so other people can benefit from your bundle. There are various tutorials for this already so I will not write on.


To give the Symfony character to your package, you will want to integrate e.g. dependency injection, expose a class as a service or use the general Symfony configuration for your services. This can easily be achieved by adding the relevant Symfony components as dependencies via composer, e.g. use command composer require symfony/dependency-injection. Afterwards, you can use them the same way you are using them in your Symfony application. Pay attention not to limit the dependency versions too much, otherwise you may prevent a user from upgrading Symfony.

There are may boni you can add to your repository, if it is published on e.g. GitHub: to give users and contributors a chance to better understand the state of your repository, integrate some of the apps and add badges to your README file.

Finally, let’s talk testing: as your package should not ship with a Kernel oder similar, you have nothing to simply run. There are workarounds: either you let your bundle live in a complete application, e.g. as a submodule, and test the application as a whole. Or you use unit-testing. If your choice falls on the latter, I can recommend using ConfigTest if your bundle uses the configuration component. Also, at one point, you may have to have an AppKernel to test the execution of a command or the availability of a route. Depending on the actual need, you can either mock the Kernel or create a TestKernel. For latter are many examples online in other bundles, e.g. in mine.

Getting started with elastica queries in Symfony

When integrating Elasticsearch with Symfony, there can be a few troubles for newcomers.

The easiest way to achieve integration is by following the setup instructions of the FOSElasticaBundle, in case you have a running Elasticsearch instance already at least. Symfony 3.1 or higher is required for this bundle. When following the setup instructions, there are a few caveats, which differed from what I expected. In the following post, I try to sketch some of the problems respectively solutions.

  • FOSElasticaBundle will not automatically recognize properties of an objectf, even when the serializer and the persistence model is defined. The properties you want to be mapped have to be listed in the configuration file.
  • To map relations such as ManyToOne, ManyToMany or OneToOne, the property gets a subkey “type” with value “nested”, after which the a new “properties” key is necessary followed by the properties of the related Entity
  • To create a development environment separat from the production index, simply set the index_name attribute of the relevant index to a environment-dependent value, such as “app_%kernel.environment%”

When you finally have the configuration set up, you have to run ./bin/console-dev fos:elastica:populate. This will show you errors in the configuration, if you have some, respectively sync your database with the elasticsearch instance.
The next step you will want to take is to use Elasticsearch to search, duh. This can get tricky at first if you are used to SQL search queries, especially as the relevant query classes are not yet as good documented as expected. The best way for me was to combine the knowledge of which classes exist with the elasticsearch documentation itself.

To translate from an SQL query to an Elastica-Query, keep the following in mind:

  • should means OR
  • must means AND
  • mustNot means XOR
  • to wrap these conditions together, use the Elastica\Query\BoolQuery
  • joins can be simulated with the Elastica\Query\Nested
  • to make comparsions with dates or numbers, use Elastica\Query\Range

With this knowledge, a query such as (...) WHERE (post.title LIKE %$search% OR creator.firstName LIKE %$search% OR creator.lastName LIKE %$search%) AND post.start < $date translates to (for example, in a custom search repository class, extends FOS\ElasticaBundle\Repository) :

setQuery($search)->setFields('firstName', 'lastName');
                $titleQuery = new Match('title', $search);
          $dateQuery = new Range('start', array('lt' => $date->format(ELASTICA_DATE_FORMAT)));

/** ... **/

This query can be executed like it is on the finder/repository yielding results. But. It will not work with a Paginator and a default number of 10 results will be returned instead. To successfully get the PaginatorAdabter, the whole BoolQuery has to be wrapped in an Elastica\Query Object.
This could be achieved e.g.:

$query = new Query();
// code from above

And to get the Pagination working:


Vaccination controversy introduced by pharma industry because they don't earn enough by vaccination

Well, at least I would like this kind of controversy/conspiracy as it would lead to the opposite effect of what the vaccination-conspiracy is leading to today. Also, this theory would be a lot more supportable by evidence, numbers and logic than the dangerous conspiracy which is spread today.

I sincerly hope that one day, people can relax a bit more over their opinions, find a common midway, depending on the issue, and stop braging with unconventional, illogical and inconsequent ideas.

Use Apple Superdrive with Windows

The Apple Superdrive drive is easy to use on Windows. However, the appropriate driver must be installed for this.

Here’s how to do it: Download the Apple Boot Camp Support Software . The file is a zip file, a “zip-compressed folder”, as Windows calls it. Unpack the file and then open the unzipped folder. Go to subfolder / BootCamp / Drivers / Apple. There you will find a file called “AppleODDInstaller64.exe” (you may not see the extension “.exe”). Use this file to install the driver by double-clicking it and following the installation wizard. That’s it! The next time you attach the Apple SuperDrive drive, your Windows should be able to recognize and work with it.

James Bond’s Salad Dressing

Mix five parts of red-wine vinegar with one part extra-virgin olive oil. The vinegar overload is essential. Add a half clove of garlic, half a teaspoon of Dijon mustard, a good grind of black pepper and a teaspoon of white granulated sugar. Mix well, remove the garlic and dress the salad.

Source: William Boyd, Solo, Jonathan Cape, London 2013, p. 269

Google und Neujahrsvorsätze

Wer im Web sucht, verrät etwas über sich – zumindest wenn er sich nicht dagegen schützt. So zeichnen Google, Bing und Co. jede Suchanfrage auf, zusammen mit Datum, Ort und welche Daten auch immer sie noch kriegen können. Zu unserem Glück bieten sie immer wieder einen Einblick in ihre Daten und zeigen Trends und Highlights, so zum Beispiel auf

Diese Daten können wichtige Erkenntnisse liefern oder einfach faszinieren. Und sie repräsentieren die Gedanken und Sorgen unserer Gesellschaft. So lässt sich zum Beispiel feststellen, dass kurz vor dem Verkaufsstart von neuen iPhones die Suchanfragen nach “iPhone langsam” exponentiell in die Höhe schnellen.

Jetzt, kurz nach Silvester, jetzt, am Anfang des neuen Jahrs, lässt sich eine ebenso rasch ansteigende Nachfrage nach “Fitness”, “abnehmen” oder “Diät” feststellen. Diese wird auch dieses Jahr – wie alle Jahre zuvor, achten Sie mal auf die Kurve – schnell wieder zurückgehen. Im Frühling wenn das Volk wieder von einer Bikinifigur träumt gehen die Suchanfragen wieder ein wenig rauf, nehmen aber auch diesmal wieder ab – bis zu den Neujahrsvorsätzen!

Welche regelmässigen Kurven finden Sie? Schreiben Sie Ihre Beobachtungen in die Kommentare!

Lesemodus – Rückentwicklung des Webs?

Immer mehr Geräte mit Internetzugang bieten im Browser die Möglichkeit, die Website ohne Style bloss als Text mit den Bildern anzuzeigen. Je nach Browser heisst diese Funktion zum Beispiel “Reader View” bzw. “Lesemodus”. Das meiner Meinung erstaunliche daran ist, dass das meiner Beobachtungen zufolge quasi ein Rückschritt auf dem Weg der Webentwicklung bedeutet. Im Lesemodus werden die Seiten, wie ganz zu Beginn des Internets, nur mit den elementarsten HTML Tags dargestellt: Nur die verschiedenen Headings, Links und Paragraphen werden angewandt. Dieser Modus macht das Lesen vielfach tatsächlich einfacher und bietet somit viel Potential. Dennoch sehe ich noch einige Schwachstellen. Einerseits werden die Webseiten dennoch ganz geladen und verbrauchen somit ebenso viel Internetleistung. Andererseits entspricht der Style des Lesemodus aus unerfindlichen Gründen nicht dem Standardstyle des Browsers – wenn also ein Developer denkt er könne es sich einfach machen und den Style einfach weg lassen, weil seine Seite einfach nur gelesen werden muss, hat sich leider getäuscht. Das Standardlayout ist noch immer voll 90er Jahre und dass der Nutzer deshalb die Reader View einschaltet ist nicht zu erwarten. Stattdessen sucht er eine andere Website auf, die ihm besser gefällt…

Haben Sie diesen Artikel im Lesemodus angeschaut? Ist Ihnen meine Meinung zu weit hergeholt? Schreiben Sie Ihre Antwort in die Kommentare!

Geistesblitz: gesamter localStorage auslesen

Für eine HTML5 Applikation hatte ich die Idee, einige Elemente im localStorage anstatt zu löschen bloss umzubenennen. Da dies mehrfach geschiehen würde, musste die Umbenennung eindeutig erfolgen, damit die anderen Elemente nicht überschrieben werden. Und was eignet sich für die eindeutige Identifikation besser als die aktuelle Uhrzeit mit Datum, Millisekunden und allem?

Nun gut; die Idee mag zwar gut klingen, aber wie kriegt man das Element eines Tages wieder aus dem Speicher raus? Wie kann ich ein Element mit nahezu zufälligem Schlüssel aufrufen?

Ja, lieber Leser, genau diese Frage habe ich mir gestellt. Bestimmt haben Sie schon nach dem Titel gedacht “Pah, das weiss ich…”. Und damit haben Sie natürlich Recht, doch da nach einer kurzen Internetrecherche meinerseits keine Lösungen auffindbar waren, möchte ich hier zwei vorstellen.

Die eine Lösung ist wohl die elegantere: jedes mal wenn man ein neues “Zufallselement” in den Storage schreibt, den entsprechenden Schlüssel in ein Array schreiben, das ebenfalls in den localStorage geschrieben wird.

Die andere Lösung ist jene, die zum Titel “Geistesblitz” geführt hat. Obwohl die Idee sehr naheliegend ist und ich früher hätte auf die Idee kommen sollen, ist sie mir halt eben als Geistesblitz gekommen. Der entscheidende Gedanke ist dieser: localStorage ist ein Objekt wie jedes andere. Also kann man es mit einer einfachen for-Schlaufe durchlaufen. Das geht zum Beispiel so, wenn alle Elemente untereinander aufgelistet werden sollen:

function listItems () {
	var string = "";
	for (var key in localStorage) {
		string += key + ": " + localStorage.getItem(key);
		string += "<br />";
	document.getElementById("target").innerHTML = string;

CSS: Windows Phone Akzentfarbe

Mit Windows (Phone) 8 gab Microsoft den Entwicklern die Möglichkeit, ihre Apps für Windows & Windows Phone mit HTML, CSS und JavaScript zu entwickeln. So ist es besonders für Webentwickler wie mich verlockend, die Web App auf jene Geräte zu portieren.

Gerade Windows Phone brilliert mit einer grossen Personalisierbarkeit; neben der Flexibilität des Sperrbildschirms, dem Hintergrundbild das den Startbildschirm vervollständigt ist auch die Akzentfarbe ein oft genanntes Argument, weshalb Windows Phone besser personalisierbar ist.

Doch wie ist es nun möglich, wenn man die App mit HTML und CSS entwickelt, auf die Akzentfarbe zuzugreifen? Die Antwort ist simpel, wenn man sie einmal gefunden hat: über die Farbe mit dem Namen Highlight. Die passende Textfarbe kann man, sehr naheliegend, mit HighlightText anwenden.