3

I am trying to add an HTML table to the bottom left corner of my Print Composer. The table is populating with data based on the current atlas feature. The problem is that the table has a different number of rows based on the atlas feature. The way the HTML table renders in composer currently it draws from the top left corner down. This means that if the box is centered for two rows and an atlas feature has a different number it is no longer lined up properly.

Is there a way to have the HTML table draw from the bottom left corner up? This way the table would still be placed properly on the page no matter the number of rows.

The only solution I have found so far is to have the whole composer draw upside down and then rotate the map back to the correct orientation after the export.

3
  • does this mean that if the # of rows to populate the table results in the covering up of the portion of the map, you're ok with that? or have you designed it to always incorporate enough white space around it to avoid that issue? i think in either case you're not going to find that ability in the html table... Commented Jul 19, 2017 at 19:04
  • If you are able to count the number of rows beforehand and save it to your atlas layer, it's possible to adjust the positioning of your table via data-defined positions
    – Nightwatch
    Commented Jul 20, 2017 at 8:05
  • @Nightwatch This may be the only solution. I would accept it if you made it an answer. This is the only solution (so far) that solves the problem of the frame/bounding box. In both HTML and the attribute table frames the table is always drawn is the top left. I was looking to circumvent this behavior. The reference point is only used by the frame/bounding box not by the item it draws.
    – Ryan Jones
    Commented Jul 20, 2017 at 14:43

1 Answer 1

3

In QGIS 3.x you could use a combination of HTML/CSS and the expression function aggregate to imitate a QGIS attribute table, that has a bottom position and only shows features of 'mylayer' which are inside the parent geometry (i.e. the current Atlas page):

<style>
table {
  position: absolute;
  bottom: 0;
  border: 0.1em solid blue;
  background-color: white;
  border-collapse:collapse;
}
th {
  color: white;
  background-color: blue;
  
}
th,td { 
  padding: 0.3em; 
  border: 0.02em solid blue;
}
</style>
<body style='margin:1em;'>
[%'<table><tr><th>Sonden</th><th>x</th><th>y</th></tr>'||

aggregate( layer:='mylayer',aggregate:='concatenate',expression:='<tr><td>'||name||'</td><td>'||x||'</td><td>'||y||'</td></tr>',filter:=contains(geometry(@parent),$geometry))

||'</table>'%]
</body>
1
  • 1
    Also use this. Just need to mention if your HTML block goes on multiple pages you will not get the table headers repeated when using <thead> (if yes, will be glad to learn how)
    – ThomasG77
    Commented Jun 18, 2020 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.